Commit 929a78f2 authored by Davis King's avatar Davis King

Changed the socket read/write code so that it can handle a large number ( > 2 billion)

of bytes in I/O calls.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403010
parent ab0e617e
...@@ -276,9 +276,14 @@ namespace dlib ...@@ -276,9 +276,14 @@ namespace dlib
{ {
const long old_num = num; const long old_num = num;
long status; long status;
const long max_send_length = 1024*1024*100;
while (num > 0) while (num > 0)
{ {
if ( (status = send(connection_socket,buf,num,0)) == SOCKET_ERROR) // Make sure to cap the max value num can take on so that if it is
// really large (it might be big on 64bit platforms) so that the OS
// can't possibly get upset about it being large.
const long length = std::min(max_send_length, num);
if ( (status = send(connection_socket,buf,length,0)) == SOCKET_ERROR)
{ {
if (sdo_called()) if (sdo_called())
return SHUTDOWN; return SHUTDOWN;
...@@ -299,7 +304,12 @@ namespace dlib ...@@ -299,7 +304,12 @@ namespace dlib
long num long num
) )
{ {
long status = recv(connection_socket,buf,num,0); const long max_recv_length = 1024*1024*100;
// Make sure to cap the max value num can take on so that if it is
// really large (it might be big on 64bit platforms) so that the OS
// can't possibly get upset about it being large.
const long length = std::min(max_recv_length, num);
long status = recv(connection_socket,buf,length,0);
if (status == SOCKET_ERROR) if (status == SOCKET_ERROR)
{ {
// if this error is the result of a shutdown call then return SHUTDOWN // if this error is the result of a shutdown call then return SHUTDOWN
......
...@@ -319,9 +319,14 @@ namespace dlib ...@@ -319,9 +319,14 @@ namespace dlib
{ {
const long old_num = num; const long old_num = num;
long status; long status;
const long max_send_length = 1024*1024*100;
while (num > 0) while (num > 0)
{ {
if ( (status = ::send(connection_socket,buf,num,0)) <=0) // Make sure to cap the max value num can take on so that if it is
// really large (it might be big on 64bit platforms) so that the OS
// can't possibly get upset about it being large.
const long length = std::min(max_send_length, num);
if ( (status = ::send(connection_socket,buf,length,0)) <=0)
{ {
// if send was interupted by a signal then restart it // if send was interupted by a signal then restart it
if (errno == EINTR) if (errno == EINTR)
...@@ -352,9 +357,14 @@ namespace dlib ...@@ -352,9 +357,14 @@ namespace dlib
) )
{ {
long status; long status;
const long max_recv_length = 1024*1024*100;
while (true) while (true)
{ {
status = recv(connection_socket,buf,num,0); // Make sure to cap the max value num can take on so that if it is
// really large (it might be big on 64bit platforms) so that the OS
// can't possibly get upset about it being large.
const long length = std::min(max_recv_length, num);
status = recv(connection_socket,buf,length,0);
if (status == -1) if (status == -1)
{ {
// if recv was interupted then try again // if recv was interupted then try again
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment