views:

89

answers:

1

i want to develop a pretty basic client-server program.

one software reads xml (or any data) and send it to the server who in turn will manipulate it a little bit and eventually will write it to the disk.

the thing is that if i have many xml files on disk (on my client side), i want to open multiple connection to the server , and not doint one by one.

my first question is : let's say i have one thread who keeps all the files handles and waitformultipleobjects on them, so it will know when one of them is ready to be read from disk. and for every file i have an appropriate socket who suppose to send that specifi file to the server. for the socket i can use the select function to know which sockets are ready for sent. but is there way to know that both the file and the appropraite socket are ready to be sent ?

second, is there a more efficient way to design the client, cuase on my current design i'm using just one thread which on multi processor computer is rather not efficient enough. (though i'm sure is till better then laucning new thread for every socket connection)

third, for the server i read about the reactor pattern. it seems appropriate but still ,like my second question, seems not effient enought while using one thread.

maybe i can use something with completion ports ? think they are pretty efficient but never really used them, so don't know exactly how.

any answers and general suggestion would be great.

+2  A: 

Take a look at boost::asio it uses a proactor pattern (see the docs) that basically uses the OS wait operations (waitforsingle/multiple,select,epoll, etc...) to make very efficient use of a single thread in a system like you're looking at implementing.

asio can read/write files as well as sockets. You could sumbit an async read for the file using asio, it would call your callback on completion then you would submit that read buffer as an async write to the socket. Asio would take care of delivering all async writes buffers as the socket completed each pending write operation.

Each of these operations is done asynchronously so the thread is only really busy to initiate reads or writes, sitting idle the rest of the time.

joshperry