This isn’t working… why not? It’s a wrapper of send() on a non-blocking
socket.
int select_send( int socket, void *buffer, int size, int flags ) {
// wrapper for send()
fd_set rfd;
struct timeval tv;
int n;
tv.tv_sec = 3;
FD_ZERO( &rfd );
FD_SET( socket, &rfd );
switch ( n = select( socket + 1, 0, &rfd, 0, &tv ) ) {
case -1:
perror(“select”);
return -1;
break;
case 0:
// time out
return -1;
break;
default:
printf( “%d descriptors ready\n”, n );
if ( FD_ISSET( socket, &rfd ) ) {
// send the data
send( socket, buffer, size, flags );
}
}
return 0;
}
“Ron Cococcia” <stopspam@mingme.com> wrote in message
news:aessao$6tb$1@inn.qnx.com…
Doug,
I’m working on the same kind of issue. You could do a couple things:
- wrap an alarm around the send(). When the alarm goes off, send() will
return an error.
- set the socket to use non blocking io (FIONBIO). Send() is blocking
because the transmit buffer is full, and if you set FIONBIO on the socket
descriptor, it will return -1 in that case and set errno to EWOULDBLOCK.
The problem I have with my application is I need to allow TCP/IP time to
transmit whatever buffers it has, as I am transmitting over the Internet.
Since TCP/IP is “guaranteed” more or less to transmit the data, I need to
let do it’s work, or eventually fail (which could be a long time).
-Ron
“Doug Rixmann” <> rixmannd@rdsdata.com> > wrote in message
news:aesrlp$6gr$> 1@inn.qnx.com> …
I am working on building an integration piece between a windows box and
a
QNX machine. This works on the same premise as ftp in that the windows
client asks for data and then opens a server connection on a specified
port.
The qnx program then connects to the port on the Windows box.
The integration is fine except that when the Windows server goes away,
the
QNX program hangs on a send command. The sockets are created
appropriately
outside the sending function.
SendToWindows( msg ) {
for each windows connection {
printf(“hello\n”);
if ( -1 == send( windows> .socket, msg ) ) {
printf(“argh!!!\n”);
perror(“argh!!!”);
}
}
}
This (of course) is not what it really looks like and yes, my list is
okay
and yes, everything is working syntactically.
What happens when the windows server goes away is that I get hung on
send.
Any thoughts?
\