> > I'm working on a TCP/IP Palm app that opens and closes *a lot*
> of sockets.
> > Unfortunately I'm running into a problem such that after
> approximately 15
> > "transactions", the next time I try to call NetLibSocketConnect() after
> > creating the socket (without any error) it returns
> > "netErrTooManyTCPConnections" (The app works fine in the
> emulator, but not
> > with the Palm modem).
>
> Yes I would also like a work-around for this.  Same problem here and it is
> preventing me from expanding the functionality of several programs.  There
> has to be a way to reset these sockets to be useable again
> without having to
> close the library.  I also tried waiting for the linger time to
> expire but it
> never has!  Even after 20 minutes, what's the deal with that..

well, i'm glad i'm not the only one ;-)

the *one* thing that i've found that works is if I do this (and have
something like a 10-15 second delay) and it's totally gross, but...:

SWord SocketCloseForcefully(NetSocketRef sock, int delay){


        SWord                           retVal;
        Err                                     err;
        NetSocketLingerType     ltype;

        //set the socket's SO_LINGER option to "0", so it'll close immediately
        //when we call NetLibSocketClose()
        ltype.onOff = true;
        ltype.time = 0;
        retVal = NetLibSocketOptionSet(AppNetRefnum, sock,
                        netSocketOptLevelSocket, netSocketOptSockLinger, &ltype,
sizeof(ltype), -1, &err);

        ASSERT(retVal == 0);

        //gracefully try and shutdown the socket by sending TCP_FIN on the socket
        retVal = NetLibSocketShutdown(AppNetRefnum, sock, netSocketDirBoth, -1,
&errno);

        ASSERT(retVal == 0);

        //give a delay here to allow the server time to acknowledge the TCP_FIN
        //before we force the socket close
        if (delay != 0)
                SysTaskDelay(delay * SysTicksPerSecond());

        //forcefully close the socket
        retVal = NetLibSocketClose(AppNetRefnum, sock, -1, &errno);

        return retVal;

}

Reply via email to