non-blocking sockets

Joseph Yip ycy at walt.cc.utexas.edu
Thu Apr 12 16:18:48 AEST 1990


I am writing some socket programs. Everything works fine except when I
want my socket to be NON-BLOCKING.

I use,

	/* to read a connected socket */
	read(socket_id,buf,BUFS);
	
Does anyone know how to read from a socket using non-blocking mode? 
recv() system call has a flag that you can PEEK at the socket. 
Do I have to go through fcntl() call to make it non-blocking?

Another question is that if I am transferring 512*512 image file using
socket,

	/* send 512*512 image file */
	write(socket_id,buf,512*512);

	......
	------------------------------------

	/* at the receiving end */
	read(socket_id,buf,512*512);

Will the receiving end receive all 512*512 bytes before returning?
What is the optimal size to send using socket?

Thank you

Joseph Yip



More information about the Comp.unix.questions mailing list