On streams sockets and efficiency

Discussion and questions about clients
Post Reply
klondike
Member
Posts: 73
Joined: 14 Nov 2010, 13:06

On streams sockets and efficiency

Post by klondike » 22 Sep 2012, 13:09

Hi,

After giving a look to the stream and socket code of DC++ I think we should try to improve it, here are some suggestions on which I'd like other's comments.

On InputStream:
Add the following methods:
bool can_mmap() /*Returns true when the input stream can be mmaped to memory*/
size_t mmap (size_t &length, const void * &buf); /*Return a pointer to the mmaped data on buf and the size of the mmaped data as result (0 when there is not more data to mmap).*/
void mmunmap (const void *buf, size_t buflen); /*Frees buf*/
bool has_handle () /*Returns true when the stream has a file handle (or an fd on UNICES) associated)*/
handle_t get_handle() /*Returns the handle associated to the stream*/

On OutputStreams:
Add the following methods:
bool can_mmap() /*Returns true when the input stream can be mmaped to memory*/
size_t mmap (size_t &length, void * &buf); /*Return a pointer to an internal buffer that will write the data to the stream when mmunmaped.*/
void mmunmap (const void *buf, size_t buflen); /*Writes data to the stream and frees buf*/
bool has_handle () /*Returns true when the stream has a file handle (or an fd on UNICES) associated)*/
handle_t get_handle() /*Returns the handle associated to the stream*/

On Sockets:
int sendstream(InputStream &in) /*Sends inputstream in an efficient way (For example using sendfile)*/
int recvstream(OutputStream &out) /*Receives the data into outputstream in an efficient way (For example using splice)*/

In the end this should help in reducing copyng overhead when transferring files since right now the file is read into a buffer then written again out resulting in a real waste of CPU and memory on some environments specially when the OS can usually take handle of that (or we can fall back to sending and receiving mmaped buffers instead with openssl sockets.

Post Reply