57#include <netinet/tcp.h>
73 if ( setsockopt(
sockfd, SOL_SOCKET, SO_RCVBUF,
74 (
char*) &
size,
sizeof(
size) ) == -1 ) {
75 perror(
"setsockopt( SO_RCVBUF )" );
79 if ( setsockopt(
sockfd, SOL_SOCKET, SO_SNDBUF,
80 (
char*) &
size,
sizeof(
size) ) == -1 ) {
81 perror(
"setsockopt( SO_SNDBUF )" );
98 if ( getsockopt(
sockfd, IPPROTO_TCP, TCP_NODELAY,
99 (
char*) &delay, &len ) == -1 ) {
100 perror(
"# getsockopt( TCP_NODELAY ) failed" );
103 return ( delay ? 1 : 0 );
115 if ( setsockopt(
sockfd, IPPROTO_TCP, TCP_NODELAY,
116 (
const char*) &delay,
sizeof(delay) ) == -1 ) {
117 perror(
"setsockopt( TCP_NODELAY ) failed" );
137 if ( setsockopt(
sockfd, IPPROTO_TCP, TCP_NODELAY,
138 (
const char*) &delay,
sizeof(delay) ) == -1 ) {
139 perror(
"setsockopt( TCP_NODELAY ) failed" );
146 if ( sendBufferSize >= 0 ) {
147 if ( setsockopt(
sockfd, SOL_SOCKET, SO_SNDBUF, (
char*) &sendBufferSize,
148 sizeof(sendBufferSize) ) == -1 ) {
149 perror(
"setsockopt( SO_SNDBUF )" );
156 if ( recvBufferSize >= 0 ) {
157 if ( setsockopt(
sockfd, SOL_SOCKET, SO_RCVBUF, (
char*) &recvBufferSize,
158 sizeof(recvBufferSize) ) == -1 ) {
159 perror(
"setsockopt( SO_RCVBUF )" );
169 int sendBufferSize,
int recvBufferSize )
179 int sockfd = socket( PF_INET, SOCK_STREAM, IPPROTO_TCP );
181 perror(
"socket() failed" );
188 struct sockaddr_in
server;
190 server.sin_family = AF_INET;
194 perror(
"connect() failure" );
204 int backlog,
bool reuse,
bool nodelay,
205 int sendBufferSize,
int recvBufferSize )
218 int sockfd = socket( AF_INET, SOCK_STREAM, 0 );
226 if ( setsockopt(
sockfd, SOL_SOCKET, SO_REUSEADDR,
227 (
char*) &opt,
sizeof(
int) ) == -1) {
228 perror(
"setsockopt( SO_REUSEADDR )" );
237 struct sockaddr_in
server;
239 server.sin_family = AF_INET;
244 fprintf( stderr,
"bind(%s): %s\n",
250 if ( listen(
sockfd, backlog ) == -1 ) {
static char server[MAXLINE]
const char * my_sock_ntoa(const struct sockaddr_in &a, SockAddress buffer)
static int commonCode(int &sockfd, bool nodelay, int sendBufferSize, int recvBufferSize)
int serverSocket(struct in_addr host, unsigned short port, int backlog, bool reuse, bool nodelay, int sendBufferSize, int recvBufferSize)
int getSocketNoDelay(int sockfd)
int setSocketNoDelay(int sockfd, bool)
int setSocketBuffers(int sockfd, int size)
int connectTo(struct in_addr host, unsigned short port, bool nodelay, int sendBufferSize, int recvBufferSize)