summaryrefslogtreecommitdiff
path: root/server/src/tcpsocket.cc
diff options
context:
space:
mode:
authordeva <deva>2007-09-03 09:11:33 +0000
committerdeva <deva>2007-09-03 09:11:33 +0000
commita34402b79b38624a29ed8ea4e059af817266e6b8 (patch)
tree4df1d9a5756e37c304ddd8b58ed3e12c4a3894c1 /server/src/tcpsocket.cc
parent27bc1afc3aa6e0b4465946aa870573499b85ae5d (diff)
Implemented the first version of the XML request. Fixed eXpat incompatability with XML_Get/SetUserData and the void* in the handler functions.
Diffstat (limited to 'server/src/tcpsocket.cc')
-rw-r--r--server/src/tcpsocket.cc32
1 files changed, 16 insertions, 16 deletions
diff --git a/server/src/tcpsocket.cc b/server/src/tcpsocket.cc
index 19470fe..6fc521f 100644
--- a/server/src/tcpsocket.cc
+++ b/server/src/tcpsocket.cc
@@ -76,7 +76,7 @@
#include <unistd.h>
#include <fcntl.h>
-Pentominos::TCPSocket::TCPSocket()
+TCPSocket::TCPSocket()
throw(TCPSocketException)
{
if((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
@@ -85,14 +85,14 @@ Pentominos::TCPSocket::TCPSocket()
isconnected = false;
}
-Pentominos::TCPSocket::~TCPSocket()
+TCPSocket::~TCPSocket()
{
disconnect();
}
static int _listen(int sockfd, int backlog){return listen(sockfd, backlog);}
-void Pentominos::TCPSocket::listen(unsigned short int port)
+void TCPSocket::listen(unsigned short int port)
throw(TCPListenException)
{
@@ -124,7 +124,7 @@ void Pentominos::TCPSocket::listen(unsigned short int port)
static int _accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
{return accept(sockfd, addr, addrlen);}
-Pentominos::TCPSocket Pentominos::TCPSocket::accept()
+TCPSocket TCPSocket::accept()
throw(TCPAcceptException)
{
TCPSocket child;
@@ -155,7 +155,7 @@ Pentominos::TCPSocket Pentominos::TCPSocket::accept()
static int _connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen)
{return connect(sockfd, serv_addr, addrlen);}
-void Pentominos::TCPSocket::connect(std::string addr, unsigned short int port)
+void TCPSocket::connect(std::string addr, unsigned short int port)
throw(TCPConnectException)
{
@@ -194,7 +194,7 @@ void Pentominos::TCPSocket::connect(std::string addr, unsigned short int port)
isconnected = true;
}
-void Pentominos::TCPSocket::disconnect()
+void TCPSocket::disconnect()
{
if(sock != -1) {
close(sock);
@@ -203,12 +203,12 @@ void Pentominos::TCPSocket::disconnect()
isconnected = false;
}
-bool Pentominos::TCPSocket::connected()
+bool TCPSocket::connected()
{
return sock != -1 && isconnected;
}
-int Pentominos::TCPSocket::read(char *buf, int size)
+int TCPSocket::read(char *buf, int size)
throw(TCPReadException)
{
int res = 0;
@@ -241,7 +241,7 @@ int Pentominos::TCPSocket::read(char *buf, int size)
return res;
}
-int Pentominos::TCPSocket::write(char *data, int size)
+int TCPSocket::write(char *data, int size)
throw(TCPWriteException)
{
if(sock == -1) {
@@ -260,7 +260,7 @@ int Pentominos::TCPSocket::write(char *data, int size)
return res;
}
-std::string Pentominos::TCPSocket::srcaddr()
+std::string TCPSocket::srcaddr()
throw(TCPNameException)
{
std::string addr;
@@ -280,7 +280,7 @@ std::string Pentominos::TCPSocket::srcaddr()
return addr;
}
-std::string Pentominos::TCPSocket::dstaddr()
+std::string TCPSocket::dstaddr()
throw(TCPNameException)
{
std::string addr;
@@ -313,13 +313,13 @@ int main()
case 0: // child
try {
- Pentominos::TCPSocket client;
+ TCPSocket client;
sleep(1); // We need to wait for the listen socket to be created.
client.connect("localhost", 12345);
sprintf(buf, "hello");
client.write(buf, sizeof(buf));
printf("Sent: [%s]\n", buf);
- } catch( Pentominos::Exception &e ) {
+ } catch( Exception &e ) {
fprintf(stderr, "%s\n", e.what());
return 1;
}
@@ -327,13 +327,13 @@ int main()
default: // parent
try {
- Pentominos::TCPSocket listen_sock;
+ TCPSocket listen_sock;
listen_sock.listen(12345);
- Pentominos::TCPSocket sock = listen_sock.accept();
+ TCPSocket sock = listen_sock.accept();
sock.read(buf, sizeof(buf));
printf("Got: [%s]\n", buf);
if(std::string(buf) != "hello") return 1;
- } catch( Pentominos::Exception &e ) {
+ } catch( Exception &e ) {
fprintf(stderr, "%s\n", e.what());
return 1;
}