Fixed timeouts in networking code

This commit is contained in:
Pauli Nieminen 2008-06-09 07:29:46 +00:00
parent 864668c9da
commit 24275c7ec8

View file

@ -290,7 +290,7 @@ static void make_network_buffer(const char* input, int len, std::vector<char>& b
static SOCKET_STATE send_buffer(TCPsocket sock, std::vector<char>& buf, int in_size = -1)
{
#ifdef __BEOS__
int timeout = 15000;
int timeout = 60000;
#endif
size_t upto = 0;
@ -331,6 +331,11 @@ static SOCKET_STATE send_buffer(TCPsocket sock, std::vector<char>& buf, int in_s
return SOCKET_READY;
}
#if defined(EAGAIN) && !defined(__BEOS__) && !defined(_WIN32)
if(errno == EAGAIN)
#elif defined(EWOULDBLOCK)
if(errno == EWOULDBLOCK)
#endif
{
// update how far we are
upto += static_cast<size_t>(res);
@ -344,7 +349,7 @@ static SOCKET_STATE send_buffer(TCPsocket sock, std::vector<char>& buf, int in_s
struct pollfd fd = { ((_TCPsocket*)sock)->channel, POLLOUT, 0 };
int poll_res;
do {
poll_res = poll(&fd, 1, 15000);
poll_res = poll(&fd, 1, 60000);
} while(poll_res == -1 && errno == EINTR);
@ -356,7 +361,7 @@ static SOCKET_STATE send_buffer(TCPsocket sock, std::vector<char>& buf, int in_s
FD_SET(((_TCPsocket*)sock)->channel, &writefds);
int retval;
struct timeval tv;
tv.tv_sec = 15;
tv.tv_sec = 60;
tv.tv_usec = 0;
do {
@ -368,7 +373,7 @@ static SOCKET_STATE send_buffer(TCPsocket sock, std::vector<char>& buf, int in_s
#elif defined(__BEOS__)
if(res > 0) {
// some data was sent, reset timeout
timeout = 15000;
timeout = 60000;
} else {
// sleep for 100 milliseconds
SDL_Delay(100);
@ -625,7 +630,6 @@ static int process_queue(void* shard_num)
result = send_file(sent_buf);
} else {
if(sent_buf->raw_buffer.empty()) {
output_to_buffer(sent_buf->sock, sent_buf->config_buf, sent_buf->stream, sent_buf->gzipped);
const std::string &value = sent_buf->stream.str();
make_network_buffer(value.c_str(), value.size(), sent_buf->raw_buffer);
}
@ -879,8 +883,7 @@ void queue_data(TCPsocket sock,const config& buf, const bool gzipped)
DBG_NW << "queuing data...\n";
buffer* queued_buf = new buffer(sock);
queued_buf->config_buf = buf;
// output_to_buffer(sock, buf, queued_buf->stream, gzipped);
output_to_buffer(sock, buf, queued_buf->stream, gzipped);
queued_buf->gzipped = gzipped;
queue_buffer(sock, queued_buf);
}