28 #include <sys/socket.h> 38 #if MSGLENGTH * 3 > BUFLENGTH 39 #error "MSGLENGTH too long" 43 #define SEND_OPTIONS 0 45 #define SEND_OPTIONS MSG_NOSIGNAL 49 const unsigned int bufsize = 2048;
50 class sockbuf :
public std::streambuf
59 char* ptr =
new char[bufsize];
60 setp(ptr, ptr + bufsize);
74 mainClass->
socket, SOL_SOCKET, SO_NOSIGPIPE, &value,
sizeof(value)))
76 Logger::log() << Logger::Error <<
"Error setting socket option. Continuing." << Logger::endl;
94 if (pbase() == epptr())
112 void put_char(
int chr)
114 Logger::log() << Logger::Error <<
"Socket::put_char is unimplemented" << Logger::endl;
119 if (pbase() != pptr())
121 int length = (pptr() - pbase());
122 char *buffer =
new char[length + 1];
124 strncpy(buffer, pbase(), length);
125 buffer[length] =
'\0';
132 setp(pbase(), epptr());
141 Socket::Socket(
int socketID ) :
142 std::ostream( new sockbuf(this) ),
143 socket(socketID), begin(0), ptrpos(0), end(0)
168 int flags = fcntl(
socket,F_GETFL);
169 fcntl(
socket,F_SETFL,flags | O_NONBLOCK);
286 int flags = fcntl( _socket, F_GETFL, 0 );
291 fcntl( _socket, F_SETFL, flags | O_NONBLOCK );
static std::ostream & endl(std::ostream &__os)
void checkBufferOverflow()