problem being faced in using winsock2's setsockopt function

int TimeOut, valsize;
setsockopt(skt,SOL_SOCKET,SO_RCVTIMEO,(const char *)&TimeOut,valsize);

firstly i make the call with TimeOut = 1000 and valsize = sizeof(TimeOut), then i make it with TimeOut = 0 and valsize=0

the first call ends up sucessfully but the second one doesnt

it gives an erorr of WSAEFAULT
(the description of error from MSDN
optval is not in a valid part of the process address space or optlen parameter is too small

optval=TimeOut, optlen = valsize

anyone who can help??

Comments

  • : int TimeOut, valsize;
    : setsockopt(skt,SOL_SOCKET,SO_RCVTIMEO,(const char *)&TimeOut,valsize);
    :
    : firstly i make the call with TimeOut = 1000 and valsize = sizeof(TimeOut), then i make it with TimeOut = 0 and valsize=0
    :
    : the first call ends up sucessfully but the second one doesnt
    :
    : it gives an erorr of WSAEFAULT
    : (the description of error from MSDN
    : optval is not in a valid part of the process address space or optlen parameter is too small
    :
    : optval=TimeOut, optlen = valsize
    :
    : anyone who can help??
    :

    First casting the address of an integer to a const char * does not seem like a good idea. Next, TimeOut is the same size no matter what it's value is, so you probably still need valsize=sizeof(TimeOut). If you mean to have TimeOut a NULL pointer then simply put NULL there, if you won't know this until runtime, then use a pointer variable.

    "Faith alone, won't sustain us anymore."
    -Faith Alone, Bad Religion

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion