Unix Programming - fcntl() - ioctlsocket()

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2004 > fcntl() - ioctlsocket()





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author fcntl() - ioctlsocket()
Wim Deprez

2004-07-28, 6:19 pm

Hi Group,

for porting issues, I need to translate a fcntl(). In the original
*nix-code the following is used:

fcntl(sd, F_SETFL, O_NONBLOCK);

to make sd a non blocking socket. Now I was wondering if

// If iMode = 0, blocking is enabled;
// If iMode != 0, non-blocking mode is enabled.
int iMode = 1;
ioctlsocket(sd, FIONBIO, (u_long FAR*) &iMode)

contains the same behaviour for win32 systems.

Many kind greetings,

--wim
Lev Walkin

2004-07-28, 6:19 pm

Wim Deprez wrote:
> Hi Group,
>
> for porting issues, I need to translate a fcntl(). In the original
> *nix-code the following is used:
>
> fcntl(sd, F_SETFL, O_NONBLOCK);
>
> to make sd a non blocking socket. Now I was wondering if
>
> // If iMode = 0, blocking is enabled;
> // If iMode != 0, non-blocking mode is enabled.
> int iMode = 1;
> ioctlsocket(sd, FIONBIO, (u_long FAR*) &iMode)
>
> contains the same behaviour for win32 systems.


You'd better ask in Winsock programming group, like
alt.winsock.programming.

However, it is easy to test: just open a connection
to a remote host and execute the following:

int r;
char buf;

r1 = read(fd, &buf, 1);

assert(r1 == -1 && errno == EAGAIN);

or something similar.

(make sure the remote host does not send anything.
www.com:80 will do).

--
Lev Walkin
vlm@lionet.info
Daniel Rakel

2004-07-28, 6:19 pm

Wim Deprez wrote:

> for porting issues, I need to translate a fcntl(). In the original
> *nix-code the following is used:
>
> fcntl(sd, F_SETFL, O_NONBLOCK);
>
> to make sd a non blocking socket. Now I was wondering if


If you only want to switch from blocking to non-blocking mode, you should
first get the current flags, add O_NONBLOCK and then set these flags.
The above code would clear the current flags set.

Regards,
Daniel
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com