Thread: select model sockets

  1. #1
    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

  2. #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.

    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

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