diff options
author | Stijn Buys <ingar@osirion.org> | 2008-03-21 19:25:11 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-03-21 19:25:11 +0000 |
commit | 2314c27dd650dc02c0b5bdd3bef75818393a9ab5 (patch) | |
tree | 231815c866a1330338d976480284250e99207554 /src/core/netclient.h | |
parent | 7e99fac4552b402034e5fc3e833cbe8c274f95ce (diff) |
switched to UDP networking
Diffstat (limited to 'src/core/netclient.h')
-rw-r--r-- | src/core/netclient.h | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/src/core/netclient.h b/src/core/netclient.h index 23a2787..2fde530 100644 --- a/src/core/netclient.h +++ b/src/core/netclient.h @@ -7,21 +7,30 @@ #ifndef __INCLUDED_CORE_NETCLIENT_H__ #define __INCLUDED_CORE_NETCLIENT_H__ +#include <unistd.h> +#include <errno.h> + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/wait.h> + +#include <netinet/in.h> +#include <arpa/inet.h> + #include <string> #include <deque> #include <map> -#include "net/tcpclient.h" #include "core/player.h" namespace core { /// queues incoming client messages -class NetClient : public net::TCPClient +class NetClient { public: - NetClient(int clientfd, std::string host, int port); + NetClient(std::string host, int port); ~NetClient(); /// the remote hostname the client is connected to @@ -33,26 +42,41 @@ public: /// the player info associated with this client Player *player(); - /// return true if there are incoming messages + /// bufer incoming data + void receive(char *data); + + /// buffer outgoing data + void send(std::string const &msg); + + /// return true if there is buffered incoming data bool has_messages() const; - /// receive an incoming message + /// retreive buffered incoming data void retreive(std::string & message); - /// receive incoming data and store messages - void receive(); + /// transmit buffered outgoing data + void transmit(); + + inline bool error() const { return client_error; } - /// buffer outgoing data - void send(std::string const &msg); + inline int fd() const { return client_fd; } - /// send bufered outgoing data - void transmit(); + void abort(); + + enum State {Connecting=0, Connected=1}; + + inline State state() const { return client_state; } + State client_state; + private: + struct sockaddr_in client_addr; std::string client_host; int client_port; Player client_player; - + bool client_error; + int client_fd; + std::string messageblock; std::deque<std::string> recvq; std::string sendq; |