Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-03-21 20:24:36 +0000
committerStijn Buys <ingar@osirion.org>2008-03-21 20:24:36 +0000
commitc11524901b338a53eee2a9f0ae9caa834a5ee76c (patch)
tree99082d805d4293706c3c0a7c67b6ee6b58a6e21a /src/core/netclient.cc
parent549f90727d321cd6cf8850e8b510beba36925a82 (diff)
single server socket
Diffstat (limited to 'src/core/netclient.cc')
-rw-r--r--src/core/netclient.cc30
1 files changed, 8 insertions, 22 deletions
diff --git a/src/core/netclient.cc b/src/core/netclient.cc
index dba6e2b..c7186f5 100644
--- a/src/core/netclient.cc
+++ b/src/core/netclient.cc
@@ -19,45 +19,31 @@ NetClient::NetClient(std::string host, int port) :
client_error = true;
client_state = Connecting;
- con_print << host << ":" << port << " connects." << std::endl;
+ con_print << host << ":" << port << " connected." << std::endl;
- // Get a socket file descriptor
- client_fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
- if (client_fd == -1) {
- con_warn << "Network client socket() failed!" << std::endl;
- abort();
- return;
- }
-
client_host = host;
client_port = port;
client_addr.sin_family = AF_INET;
client_addr.sin_port = htons(port);
client_addr.sin_addr.s_addr = inet_addr(host.c_str());
+ memset(client_addr.sin_zero, '\0', sizeof(client_addr.sin_zero));
+
if (client_addr.sin_addr.s_addr == INADDR_NONE) {
con_warn << "Network invalid client address " << host << "!" << std::endl;
abort();
return;
}
- memset(client_addr.sin_zero, '\0', sizeof(client_addr.sin_zero));
-
- std::ostringstream osstream;
- client_player.player_id = client_fd;
-
+
sendq.clear();
messageblock.clear();
-
+
client_error = false;
}
NetClient::~NetClient()
{
- con_print << host() << ":" << port() << " disconnects." << std::endl;
-
- if (client_fd) {
- ::close(client_fd);
- }
+ con_print << host() << ":" << port() << " disconnected." << std::endl;
}
void NetClient::abort()
@@ -124,7 +110,7 @@ void NetClient::send(std::string const &msg)
sendq.append(msg);
}
-void NetClient::transmit()
+void NetClient::transmit(int serverfd)
{
if (sendq.size() >= BLOCKSIZE) {
con_warn << "Outgoing message exceeds " << BLOCKSIZE << " bytes!\n";
@@ -135,7 +121,7 @@ void NetClient::transmit()
ssize_t bytes_sent = 0;
while (sendq.size() && !error()) {
- bytes_sent = sendto(client_fd, sendq.c_str(), sendq.size(), 0,
+ bytes_sent = sendto(serverfd, sendq.c_str(), sendq.size(), 0,
(struct sockaddr *)&client_addr, sizeof(client_addr));
if (bytes_sent < 0) {