35 #include <sys/types.h>
36 #include <sys/socket.h>
37 #include <arpa/inet.h>
53 _socket(socket), _connected(true), _listening(false), _addr_set(true)
58 switch (addr->sa_family) {
60 inet_ntop(AF_INET, &(((
struct sockaddr_in *) addr)->sin_addr), ip,
sizeof(ip));
61 port = ntohs (((
struct sockaddr_in *)addr)->sin_port);
64 inet_ntop(AF_INET6, &(((
struct sockaddr_in6 *) addr)->sin6_addr), ip,
sizeof(ip));
65 port = ntohs (((
struct sockaddr_in6 *)addr)->sin6_port);
68 snprintf(ip,
sizeof(ip),
"UNKNOWN FAMILY: %d", addr->sa_family);
88 string send_str = str.substr(start, end);
89 int bytes_written = write(
_socket, send_str.c_str(), send_str.length());
90 if (bytes_written == -1) {
91 string err(
"socket failure, writing on stream socket");
92 const char* error_info = strerror(errno);
93 if (error_info) err +=
" " + (string) error_info;
105 while ((bytesRead = read(
_socket, inBuff, inSize)) < 1) {
106 if (errno == EINTR || errno == EAGAIN) {
110 *(
BESLog::TheLog()) <<
"Socket::receive: errno: " << strerror(errno) <<
", bytesRead: " << bytesRead << endl;
116 std::ostringstream oss;
117 oss <<
"Socket::receive: socket failure, reading on stream socket: " << strerror(errno) <<
", bytesRead: "
121 else if (bytesRead == 0)
136 strm <<
BESIndent::LMarg <<
"Socket::dump - (" << (
void *)
this <<
")" << endl;
exception thrown if inernal error encountered
virtual void send(const std::string &str, int start, int end)
virtual void dump(ostream &strm) const
dumps information about this object
static ostream & LMarg(ostream &strm)
virtual int receive(char *inBuff, const int inSize)