C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 05-15-2006, 07:49 AM   #1
l2u
Registered User
 
Join Date: May 2006
Posts: 630
select model sockets

Hey

I work on a select model socket client, where I have many outgoing connections that are being handled by 1 thread. Is there anything that I should be aware of when im doing send and recv call?
Are there any possibilities I wouldnt get all the data when socket is ready to read?

I have made a socket class where I have information for each socket stored. Would it be better to make a pointer char for recv buf in a class, when recieving data on read call. Is there any need for that? Would it be smart to use ioctl(The_Socket, FIONREAD, &num_bytes); to get the number of bytes that are ready to read, to allocate the memory in the buffer or just allocate some number, and then loop with recv?

Also another question, would it be better to loop when sending data till all data is sent like

Code:
do {
			ret=send(The_Socket,buf,count,0);

			count-=ret;
			buf+=ret;
		} while(count>0);
or just normal send, and store with char pointer if there is data that wasnt sent out yet?

Thanks a lot for your help
l2u is offline   Reply With Quote
Old 05-15-2006, 08:18 AM   #2
Registered User
 
Join Date: Jan 2005
Posts: 847
Quote:
Originally Posted by l2u
Are there any possibilities I wouldnt get all the data when socket is ready to read?
Yes more data can be available after your recv has returned. But your next call to select will show that socket is now readable so you can just wait till the next select call to get the next chunk of available data.

Quote:
Would it be smart to use ioctl(The_Socket, FIONREAD, &num_bytes); to get the number of bytes that are ready to read, to allocate the memory in the buffer or just allocate some number, and then loop with recv?
Have a buffer, say 1024 bytes and loop till it is filled. This will avoid lots of memory allocations/frees.


Check your platforms documentations for send, it may not be necercary to loop.
Quantum1024 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
brace-enclosed error jdc18 C++ Programming 53 05-03-2007 05:49 PM
program structure with select sockets n3v Networking/Device Communication 9 06-03-2006 06:34 AM
multiple UDP sockets with select() nkhambal Networking/Device Communication 2 01-17-2006 07:36 PM
Help with file reading/dynamic memory allocation Quasar C++ Programming 4 05-17-2004 03:36 PM
FAQ: Directional Keys - Useing in Console RoD FAQ Board 38 10-06-2002 04:42 PM


All times are GMT -6. The time now is 02:54 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22