diff options
Diffstat (limited to 'src/core/netclient.cc')
| -rw-r--r-- | src/core/netclient.cc | 21 | 
1 files changed, 15 insertions, 6 deletions
diff --git a/src/core/netclient.cc b/src/core/netclient.cc index f75d8f3..253cf4f 100644 --- a/src/core/netclient.cc +++ b/src/core/netclient.cc @@ -18,19 +18,24 @@  namespace core  { -NetClient::NetClient(std::string host, int port) : +NetClient::NetClient(std::string host, int port, int fd) :  		client_host(host)  {  	client_error = true;  	client_state = Connecting; +	client_fd = fd; +	client_host = host; +	client_port = port;  	client_player = new NetPlayer(this); +	if (!fd) { +		con_warn << "Network invalid client file descriptor!" << std::endl; +		abort(); +		return; +	}  	con_print << host  << ":" << port << " connected." << std::endl; -	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()); @@ -120,10 +125,14 @@ void NetClient::send_raw(std::string const &msg)  	if (error())  		return; +	if ((sendq.size()) && (sendq.size() + msg.size() >= BLOCKSIZE - 16 )) { +		transmit(); +	} +  	sendq.append(msg);  } -void NetClient::transmit(int serverfd) +void NetClient::transmit()  {  	if (!sendq.size()) {  		if (client_keepalive + NETTIMEOUT/2 < application()->time()) { @@ -166,7 +175,7 @@ void NetClient::transmit(int serverfd)  	size_t		total_sent = 0;  	while (total_sent < total_size && !error()) { -		ssize_t bytes_sent = ::sendto(serverfd, data, total_size - total_sent, 0, +		ssize_t bytes_sent = ::sendto(fd(), data, total_size - total_sent, 0,  				(struct sockaddr *)&client_addr, sizeof(client_addr));  		if (bytes_sent < 0) {  | 
