diff options
author | Martin Peach <mrpeach@users.sourceforge.net> | 2009-03-02 03:41:49 +0000 |
---|---|---|
committer | Martin Peach <mrpeach@users.sourceforge.net> | 2009-03-02 03:41:49 +0000 |
commit | 4fd4a8e393efd1c5ec6fbeaa3f5a7ff4706e0d28 (patch) | |
tree | f633b0a5d6ccc7d6cdb73bd1004e9ad89ef5ec74 | |
parent | ae4c8ee2ca0405b421271ee2a3f4a35d08e05103 (diff) |
tcpserver_send_buf: send only one byte at a time into the buffer to avoid buffer overflow. This should not slow the whole thing down too much since we're already passing things one byte at a time.
svn path=/trunk/externals/mrpeach/; revision=10827
-rw-r--r-- | net/tcpserver.c | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/net/tcpserver.c b/net/tcpserver.c index 79fba19..48f55a1 100644 --- a/net/tcpserver.c +++ b/net/tcpserver.c @@ -402,7 +402,7 @@ static size_t tcpserver_send_buf(int client, int sockfd, char *byte_buf, size_t } if (FD_ISSET(sockfd, &wfds)) { - result = send(sockfd, byte_buf, (int)(length-sent), 0); + result = send(sockfd, bp, 1, 0);/*(sockfd, bp, (int)(length-sent), 0);*/ if (result <= 0) { sys_sockerror("tcpserver: send"); @@ -591,11 +591,11 @@ static int tcpserver_get_socket_send_buf_size(int sockfd) int optVal = 0; int optLen = sizeof(int); #ifdef MSW - if (getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (char*)&optVal, &optLen) == SOCKET_ERROR)
- post("%_get_socket_send_buf_size: getsockopt returned %d\n", objName, WSAGetLastError());
+ if (getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (char*)&optVal, &optLen) == SOCKET_ERROR) + post("%_get_socket_send_buf_size: getsockopt returned %d\n", objName, WSAGetLastError()); #else - if (getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (char*)&optVal, &optLen) == -1)
- post("%_get_socket_send_buf_size: getsockopt returned %d\n", objName, errno);
+ if (getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (char*)&optVal, &optLen) == -1) + post("%_get_socket_send_buf_size: getsockopt returned %d\n", objName, errno); #endif return optVal; } @@ -606,11 +606,11 @@ static int tcpserver_set_socket_send_buf_size(int sockfd, int size) int optVal = size; int optLen = sizeof(int); #ifdef MSW - if (setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (char*)&optVal, optLen) == SOCKET_ERROR)
- post("%s_set_socket_send_buf_size: setsockopt returned %d\n", objName, WSAGetLastError());
+ if (setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (char*)&optVal, optLen) == SOCKET_ERROR) + post("%s_set_socket_send_buf_size: setsockopt returned %d\n", objName, WSAGetLastError()); #else - if (setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (char*)&optVal, optLen) == -1)
- post("%s_set_socket_send_buf_size: setsockopt returned %d\n", objName, errno);
+ if (setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (char*)&optVal, optLen) == -1) + post("%s_set_socket_send_buf_size: setsockopt returned %d\n", objName, errno); #endif else return (tcpserver_get_socket_send_buf_size(sockfd)); } @@ -735,21 +735,21 @@ static void tcpserver_connectpoll(t_tcpserver *x) post("%s: accepted connection from %s on socket %d", objName, x->x_host[i]->s_name, x->x_fd[i]); /* see how big the send buffer is on this socket */ - x->x_fdbuf[i] = 0;
-#ifdef MSW
- if (getsockopt(x->x_fd[i], SOL_SOCKET, SO_SNDBUF, (char*)&optVal, &optLen) != SOCKET_ERROR)
- {
- /* post("%s_connectpoll: send buffer is %ld\n", objName, optVal); */
- x->x_fdbuf[i] = optVal;
- }
- else post("%s_connectpoll: getsockopt returned %d\n", objName, WSAGetLastError());
+ x->x_fdbuf[i] = 0; +#ifdef MSW + if (getsockopt(x->x_fd[i], SOL_SOCKET, SO_SNDBUF, (char*)&optVal, &optLen) != SOCKET_ERROR) + { + /* post("%s_connectpoll: send buffer is %ld\n", objName, optVal); */ + x->x_fdbuf[i] = optVal; + } + else post("%s_connectpoll: getsockopt returned %d\n", objName, WSAGetLastError()); #else - if (getsockopt(x->x_fd[i], SOL_SOCKET, SO_SNDBUF, (char*)&optVal, &optLen) == 0)
- {
- /* post("%s_connectpoll: send buffer is %ld\n", objName, optVal); */
- x->x_fdbuf[i] = optVal;
- }
- else post("%s_connectpoll: getsockopt returned %d\n", objName, errno);
+ if (getsockopt(x->x_fd[i], SOL_SOCKET, SO_SNDBUF, (char*)&optVal, &optLen) == 0) + { + /* post("%s_connectpoll: send buffer is %ld\n", objName, optVal); */ + x->x_fdbuf[i] = optVal; + } + else post("%s_connectpoll: getsockopt returned %d\n", objName, errno); #endif outlet_float(x->x_connectout, x->x_nconnections); outlet_float(x->x_sockout, x->x_fd[i]); /* the socket number */ |