View mode: basic / threaded / horizontal-split · Log in · Help
February 08, 2005
Can't get nonblocking socket.
Error: Unable to set socket blocking.

I was googlin' for that but I can't find what am I doing wrong. Maybe
someone can give me some advise.

I've found this only:
http://www.digitalmars.com/d/archives/digitalmars/D/2658.html

I've got glibc 2.3.4 - can be this similar problem?

Regards,
-- 
Dawid Ciężarkiewicz | arael
jid: arael@fov.pl
February 08, 2005
Re: Can't get nonblocking socket.
On Tue, 08 Feb 2005 16:10:46 +0100, Dawid Ciężarkiewicz <arael@fov.pl>  
wrote:
> Error: Unable to set socket blocking.
>
> I was googlin' for that but I can't find what am I doing wrong. Maybe
> someone can give me some advise.
>
> I've found this only:
> http://www.digitalmars.com/d/archives/digitalmars/D/2658.html
>
> I've got glibc 2.3.4 - can be this similar problem?

It does look like the same problem. I looked in std.socket and I see:

# void blocking(bit byes)
# {
# 	version(Win32)
# 	{
# 		uint num = !byes;
# 		if(SOCKET_ERROR == ioctlsocket(sock, FIONBIO, &num))
# 			goto err;
# 		_blocking = byes;
# 	}
# 	else version(BsdSockets)
# 	{
# 		int x = fcntl(handle, F_GETFL, 0);
# 		if(byes)
# 			x &= ~O_NONBLOCK;
# 		else
# 			x |= O_NONBLOCK;
# 		if(SOCKET_ERROR == fcntl(sock, F_SETFL, x))
# 			goto err;
# 	}
# 	return; //success
#
# 	err:
# 	throw new SocketException("Unable to set socket blocking.");
# }

which is the error you're getting.

I notice it's using fcntl to set the blocking state of the socket. On  
error it sets errno, so retrieving errno and/or the error message  
associated might tell us more.

To do so call strerror(errno). See the attached file for an example.  
Ideally add this error string to the exception throw. You'd have to change  
std.socket and rebuild phobos.


I have some code here which uses the 'ioctl' function instead of fcntl, eg.

int nonblock = 1;
ioctl(sock,FIONBIO,nonblock);

so you/we could also try that. You'd have to change std.socket and rebuild  
phobos.


Regan
Top | Discussion index | About this forum | D home