On Thu, 27 May 2004 18:28:09 +1000
"Brad Douglas" <[EMAIL PROTECTED]> wrote:

> Hi All,
> 
> I'm having some trouble trying to set a TCP socket to non-blocking 
> (code example below). 

Is that really what you want? Maybe using poll() or select() would
be a better option.

> Basically fnctl is returning -1 but when I 
> try and get the errno, it's set to 0 (which I beleive is success).

I'm not sure fcntl() works on sockets, I thought you had to use an ioctl().
This link:

     http://www.developerweb.net/sock-faq/detail.php?id=63

suggests that either works.

> I've done a quick walk through with another hacker here but we cant' see anything 
> obvious.
> 
> Any ideas on what I've balls up is greatly appreciated.
> 
> Regards,
> Brad
> 
> #include <sys/socket.h>
> #include <netinet/in.h>
> #include <netdb.h>
> #include <errno.h>
> #include <string.h>
> #include <stdio.h>
> #include <fcntl.h>
> 
> int main()
> {
>     int fileDescriptor = socket(AF_INET, SOCK_STREAM, 0);
>     if ( 0 > fileDescriptor )
>         printf("Unable to obtain new socket (errn = %d, text = \"%s\"\n",
>                 errno, strerror(errno));

Errrm, all you have is a socket, its not connected to anything. Maybe you
could connect() or accept() on the socket before you set it to non-blocking.

Erik
-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo  [EMAIL PROTECTED] (Yes it's valid)
+-----------------------------------------------------------+
A good debugger is no substitue for a good test suite.
-- 
-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo  [EMAIL PROTECTED] (Yes it's valid)
+-----------------------------------------------------------+
A good debugger is no substitue for a good test suite.
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to