summaryrefslogtreecommitdiff
path: root/server/src/tcpsocket.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/tcpsocket.cc')
-rw-r--r--server/src/tcpsocket.cc34
1 files changed, 12 insertions, 22 deletions
diff --git a/server/src/tcpsocket.cc b/server/src/tcpsocket.cc
index 818934e..f748e0a 100644
--- a/server/src/tcpsocket.cc
+++ b/server/src/tcpsocket.cc
@@ -90,14 +90,12 @@ TCPSocket::TCPSocket(std::string name, int sock)
isconnected = false;
this->sock = sock;
- PRACRO_DEBUG(socket, "TCPSocket %s: %p %d (%d)\n", name.c_str(),
- this, sock, getpid());
+ PRACRO_DEBUG(socket, "TCPSocket %s: %p %d (%d)\n", name.c_str(), this, sock, getpid());
}
TCPSocket::~TCPSocket()
{
- PRACRO_DEBUG(socket, "~TCPSocket %s: %p %d (%d)\n", name.c_str(),
- this, sock, getpid());
+ PRACRO_DEBUG(socket, "~TCPSocket %s: %p %d (%d)\n", name.c_str(), this, sock, getpid());
disconnect();
}
@@ -111,7 +109,7 @@ void TCPSocket::listen(unsigned short int port)
if(isconnected) throw TCPListenException("Socket alread connected.");
struct sockaddr_in socketaddr;
- memset((char *) &socketaddr, 0, sizeof(socketaddr));
+ memset((char *) &socketaddr, sizeof(socketaddr), 0);
socketaddr.sin_family = AF_INET;
socketaddr.sin_port = htons(port);
socketaddr.sin_addr.s_addr = htonl(INADDR_ANY);
@@ -161,32 +159,27 @@ TCPSocket *TCPSocket::accept()
}
}
if(FD_ISSET(sock, &fset)) {
- int csock = _accept(sock, (struct sockaddr*)&ssocketaddr,
- (socklen_t*)&csalen);
+ int csock = _accept(sock, (struct sockaddr*)&ssocketaddr, (socklen_t*)&csalen);
TCPSocket *child = new TCPSocket(name + "-child", csock);
if (child->sock == -1) {
- throw TCPAcceptException(std::string("accept failed - ") +
- strerror(errno));
+ throw TCPAcceptException(std::string("accept failed - ") + strerror(errno));
}
child->isconnected = true;
return child;
} else {
- PRACRO_ERR_LOG(socket, "Accept returned with no socket"
- " - This should not happen!\n");
+ PRACRO_ERR_LOG(socket, "Accept returned with no socket - This should not happen!\n");
return NULL;
}
}
-static int _connect(int sockfd, const struct sockaddr *serv_addr,
- socklen_t addrlen)
+static int _connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen)
{return connect(sockfd, serv_addr, addrlen);}
void TCPSocket::connect(std::string addr, unsigned short int port)
throw(TCPConnectException)
{
- if(isconnected)
- throw TCPConnectException("Socket already connected.", "", "");
+ if(isconnected) throw TCPConnectException("Socket already connected.", "", "");
#ifndef BYPASS_STATICALLOCATIONS
// Do DNS lookup
@@ -198,8 +191,7 @@ void TCPSocket::connect(std::string addr, unsigned short int port)
char portno[32];
sprintf(portno, "%d", port);
throw TCPConnectException(addr, portno,
- std::string("host lookup failed: ") +
- hstrerror(h_errno));
+ std::string("host lookup failed: ") + hstrerror(h_errno));
}
addr_list = (struct in_addr **)he->h_addr_list;
@@ -210,7 +202,7 @@ void TCPSocket::connect(std::string addr, unsigned short int port)
#endif/*BYPASS_STATICALLOCATIONS*/
struct sockaddr_in socketaddr;
- memset((char *) &socketaddr, 0, sizeof(socketaddr));
+ memset((char *) &socketaddr, sizeof(socketaddr), 0);
socketaddr.sin_family = AF_INET;
socketaddr.sin_port = htons(port);
socketaddr.sin_addr.s_addr = inet_addr(ip);
@@ -227,8 +219,7 @@ void TCPSocket::connect(std::string addr, unsigned short int port)
void TCPSocket::disconnect()
{
if(sock != -1) {
- PRACRO_DEBUG(socket, "Closing TCPSocket %s: %p %d (%d)\n",
- name.c_str(), this, sock, getpid());
+ PRACRO_DEBUG(socket, "Closing TCPSocket %s: %p %d (%d)\n", name.c_str(), this, sock, getpid());
int ret = close(sock);
if(ret == -1) {
perror(name.c_str());
@@ -305,8 +296,7 @@ int TCPSocket::read(char *buf, int size, long timeout)
return res;
}
-ssize_t _write(int fd, const void *buf, size_t count)
-{ return write(fd, buf, count); }
+ssize_t _write(int fd, const void *buf, size_t count) { return write(fd, buf, count); }
int TCPSocket::write(char *data, int size)
throw(TCPWriteException)
{