Hi All,
I'm having some trouble trying to set a TCP socket to non-blocking (code example
below). Basically fnctl is returning -1 but when I try and get the errno, it's set to
0 (which I beleive is success).
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));
int currentFlags = fcntl(fileDescriptor, F_GETFL, 0);
if ( 0 > currentFlags )
printf("Unable to get current file descriptor flags\n");
int returnCode = fcntl(fileDescriptor, F_SETFL, currentFlags | O_NONBLOCK);
if ( -1 == returnCode );
printf("Unable to set file descriptor flags (errno = %d, text = \"%s\")\n",
errno, strerror(errno));
return 0;
}
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html