Hi

I'm trying to convert an old MS-Windows program I'd written into Linux, and the program uses Non-Blocking communication.

Although the connection itself does work under Linux, the "Non Blocking" part does not.
It's still working as a blocking.

This is the code I'm making (translated for this message, from several files and higher functions I made for this):

..
void error (char *msg[]) {
        printf ("%s\n",msg);
        halt(-1);
}
..
char *Tr[] = "TRUE";
int sock = socket (AF_INET, SOCK_STREAM, 0);
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, TR, strlen (Tr));

addr.family = AF_INET;
addr.addr = 0;
addr.port := portno;

if (!bind(sock, &addr, sizeof(addr)))
        error("ERROR on binding")

if (!listen(sock,5))
     error("ERROR on listening");

siz:=sizeof(addr);
nsfd:=accept(sock, &addr, &siz);

if (!nsfd)
     error("ERROR on accept");

opt = fcntl(nsfd, F_GETFD);
if (!opt)
        error("ERROR on getFD");

if (!fpfcntl(nsfd, F_SETFD, opt | O_NONBLOCK))
        error('ERROR on setFD');

do {
        printf("Receiving\n");
      buffer ="";
      n:=recv(nsfd, &buffer, 255, 0);

      if (!n)
        printf ("ERROR reading from socket: ");

      if (n)
        printf("%s\n",buffer);

      send(nsfd, @buffer, strlen(buffer), 0);
}
while (1);
..

I edit it here for the email without testing) because of higher functions I'm using that do this work exactly (I took the content of the functions...).

The problem is that "receiving" should display all the time without stopping, While in the real running it stops until I do accept data from the client.

Any help on the matter will help very much (including a good document),


Ido -- "Being on the tightrope is living; everything else is waiting." Karl Wallenda

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Reply via email to