tcp/ip communications

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?_

Doug Rixmann wrote:

Any thoughts?

As Ron suggested use non blocking sockets for this. Under QNX6 you
would have the nicer option of doing a TimerTimeout() allowing the send
to unblock after some period of time. Of course, you would still need
to determine what constitutes “too long” a time (which is Rons’
dilemma). Under QNX4, the only reasonably elegant solution is non
blocking sockets.

Rennie

Doug,
I’m working on the same kind of issue. You could do a couple things:

  1. wrap an alarm around the send(). When the alarm goes off, send() will
    return an error.
  2. 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?

First of all, I assume the “socket” is a tcp (SOCK_SREAM), udp
have different behave.

It is not “hang”, but just tcp is retring. It took tcp about
10 minutes to decided the other side is “down”, and give up,
and then an error will return to your “send()”.

If block for 10 minutes is too long for you, then yes, normally
a non-block socket could help. But you still have to come back
to see if you “can send” if you got EWOULDBLOCK.

A better solution is use “select()” on the socket. (and if
your program do “Receive()”, you either play with select_receive(),
or check out the sample how to turn select() into a proxy).

-xtang

Ron Cococcia <stopspam@mingme.com> wrote:

Doug,
I’m working on the same kind of issue. You could do a couple things:

  1. wrap an alarm around the send(). When the alarm goes off, send() will
    return an error.
  2. 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?

Thanks Ron. I’m looking at the select() function as well. Could check into
the status before the send. Perhaps a call to select() could tell me if the
socket was still writable?

I’m going with the non-blocking call though for now.



“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:

  1. wrap an alarm around the send(). When the alarm goes off, send() will
    return an error.
  2. 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?

\

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:

  1. wrap an alarm around the send(). When the alarm goes off, send() will
    return an error.
  2. 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?

\