Thanks for the reply, I do a shutdown and then a close on the socket at the
bottom of this routine. This method is called in a loop that is reading
from a database..
Thanks again
static Err Upload(Char buf[], Char fileName[])
{
Err err;
UInt16 netLib;
UInt16 ifErrs;
NetSocketRef socket;
Int16 result;
NetSocketAddrINType destAddr;
Char errMessage[100];
FileRef fileRef=NULL;
UInt32 numBytesRead=0;
NetLibAddressType address;
// Find the network library
err = SysLibFind("Net.lib", &netLib);
if (err)
{
//msg
return err;
}
// Get and validate the destination
if (!GetAddr(netLib, &address.addr, &address.port)) {
FrmCustomAlert(ErrorMessageAlert,"Failed to validate destination
address.","","");
return 1;
}
// Open the network library
err = NetLibOpen(netLib, &ifErrs);
if (ifErrs || (err && err != netErrAlreadyOpen))
{
goto CloseNetLib;
}
UInt16 timeoutTicks = SysTicksPerSecond()*360;
// Open a socket
socket = NetLibSocketOpen(netLib, // Network library
netSocketAddrINET, // Address domain
netSocketTypeStream, // Socket type
netSocketProtoIPTCP, // Protocol
timeoutTicks, // Timeout
&err // Error result
);
if (err)
{
goto CloseNetLib;
}
NetSocketLingerType linga;
linga.onOff = true; //true means on
linga.time = 0; //seconds.
result = ::NetLibSocketOptionSet( netLib
, socket
, netSocketOptLevelSocket
, netSocketOptSockLinger
, &linga
, sizeof(linga)
, timeoutTicks
, &err
);
if (err)
{
goto CloseSocket;
}
// Connect the socket to its destination
MemSet(&destAddr, sizeof(destAddr), 0);
destAddr.family = netSocketAddrINET; // This should match the second
argument to NetLibSocketOpen
destAddr.port = address.port;
destAddr.addr = address.addr;
err = 0;
result = NetLibSocketConnect(netLib, // Network library
socket, // Socket
reference
(NetSocketAddrType*)&destAddr, //
Destination address
sizeof(destAddr), // Length of
destAddr
timeoutTicks, //
Timeout
&err // Error result
);
// Send customer data
UInt16 sentBytes = 0;
UInt16 bytesToSend = 0;
result = 0;
bytesToSend = gCustDataLen+1;
while (sentBytes < bytesToSend) {
result = NetLibSend (netLib, // Network library
socket, // Socket reference
buf + sentBytes, // Buffer to send
bytesToSend
- sentBytes, // Bytes to send from buffer
0, // Flags
NULL, // Destination address --
does not apply to TCP sockets
0, // Length of destination
address
timeoutTicks, // Timeout
&err // Error result
);
if (result == -1) {
break;
}
sentBytes += result;
}
if (err)
{
goto CloseSocket;
}
Err closeError;
// Close the socket
CloseSocket:
result = NetLibSocketShutdown (netLib,
socket,
netSocketDirBoth,
timeoutTicks,
&closeError) ;
if (!err && closeError)
{
StrPrintF(errMessage,"Problem shutting down socket. Error:
%d",closeError);
FrmCustomAlert(ErrorMessageAlert,errMessage,"","");
return closeError;
}
result = NetLibSocketClose (netLib, // Network Library
socket, // Socket reference
-1, // Timeout
&closeError // Error result
);
if (!err && closeError)
{
StrPrintF(errMessage,"Problem closing socket. Error: %d",closeError);
FrmCustomAlert(ErrorMessageAlert,errMessage,"","");
return closeError;
}
SysTaskDelay(5 * SysTicksPerSecond());
// Close the network library
CloseNetLib:
closeError = NetLibClose(netLib, false);
if (!err && closeError)
{
StrPrintF(errMessage,"Problem closing network library. Error:
%d",closeError);
FrmCustomAlert(ErrorMessageAlert,errMessage,"","");
return closeError;
}
return err;
}
"Palm Dev Forum" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> You still have to close the socket after setting this parameter. We set
> the linger flag first when setting up the socket, then do the necessary
> operations, then close the socket. We can open 1 socket at a time as
fast
> as cpu will take it. We've never tested multiple sockets open - we don't
> need that feature.
>
> If you are, you should post the whole socket operations, as this should
work
> fine.
> --------------------------------------------------------------------
> Gary Gorsline
> Easy Business Software
> ========================== End of Message ==========================
>
> ----- Original Message -----
> From: "T." <[EMAIL PROTECTED]>
> Newsgroups: palm-dev-forum
> To: "Palm Developer Forum" <[EMAIL PROTECTED]>
> Sent: Friday, August 29, 2003 9:21 AM
> Subject: netErrTooManyTCPConnections
>
>
> > Hi group, I've reviewed the many postings on this problem and am using:
> >
> > NetSocketLingerType linga;
> > linga.onOff = true; //true means on
> > linga.time = 0; //seconds.
> > result = NetLibSocketOptionSet( netLib
> > , socket
> > , netSocketOptLevelSocket
> > , netSocketOptSockLinger
> > , &linga
> > , sizeof(linga)
> > , timeoutTicks
> > , &err
> > );
> > to force each socket to shut down. I'm also using a SysTaskDelay(5) to
> > allow the OS a chance to work, but I continue to rec the
> > netErrTooManyTCPConnections error after about 16 iterations of a send
> loop.
> > Has there been any new insight on this? I'm using Palm 5, Codewarrior
9,
> > and the Clie PEG NZ-90. Thanks for any thoughts.
> >
> >
> >
> > --
> > For information on using the Palm Developer Forums, or to unsubscribe,
> please see http://www.palmos.com/dev/support/forums/
> >
>
>
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/