This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

NDK setsockopt

I was wondering how socket options such as SO_REUSEADDR are unset in the NDK. I'm also wondering about SO_RCVTIMEO.  If I want to set it back to wait forever would I set it to SYS_FOREVER(-1) or perhaps 0.

Is there any documentation that is more detailed than spru524?

 

Thanks,

-Mike

  • Mike,

    I've never done this but I can guess.  I took a look at the setsockoption code, here's an excerpt:


    //--------------------------------------------------------------------
    // SockSet()
    //
    // Set Socket Parameter Value
    //--------------------------------------------------------------------
    int SockSet(HANDLE hSock, int Type, int Prop, void *pbuf, int size)
    {

        ...

        // For the remainder, the property value is an int
        if( size < sizeof(int) )
            return( EINVAL );

        value = *(int *)pbuf;

        switch( Prop )
        {

        ...
        case SO_DEBUG:
        case SO_KEEPALIVE:
        case SO_DONTROUTE:
        case SO_USELOOPBACK:
        case SO_BROADCAST:
        case SO_REUSEADDR:
        case SO_REUSEPORT:
        case SO_OOBINLINE:
        case SO_TIMESTAMP:
            if( value )
                ps->OptionFlags |= (uint)Prop;
            else
                ps->OptionFlags &= (uint)~Prop;
      // -> I think this should "un-set" the option for you
            break;

    Based on the above code, I think you need to call setsockoption() using SO_REUSEADDR but put a value of zero into pbuf.  This should cause the above if (value) statement to be false, and will then AND the 1's compliment of SO_REUSEADDR with the OptionsFlags, which will unset that bit.

     

    Steve