mirror of
https://github.com/Tiiffi/mcrcon.git
synced 2025-12-17 02:32:54 -05:00
Add a net_recv_all() function to ensure complete receives at all times
This commit is contained in:
13
mcrcon.c
13
mcrcon.c
@@ -84,6 +84,7 @@ void net_init_WSA(void);
|
|||||||
void net_close(int sd);
|
void net_close(int sd);
|
||||||
int net_connect(const char *host, const char *port);
|
int net_connect(const char *host, const char *port);
|
||||||
bool net_send_packet(int sd, rc_packet *packet);
|
bool net_send_packet(int sd, rc_packet *packet);
|
||||||
|
ssize_t net_recv_all(int sockfd, void *buf, size_t len);
|
||||||
rc_packet* net_recv_packet(int sd);
|
rc_packet* net_recv_packet(int sd);
|
||||||
|
|
||||||
// Misc stuff
|
// Misc stuff
|
||||||
@@ -422,6 +423,18 @@ bool net_send_packet(int sd, rc_packet *packet)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssize_t net_recv_all(int sockfd, void *buf, size_t len)
|
||||||
|
{
|
||||||
|
size_t total = 0;
|
||||||
|
|
||||||
|
while (total < len) {
|
||||||
|
ssize_t n = recv(sockfd, (char*) buf + total, len - total, 0);
|
||||||
|
if (n <= 0) return n; // error or closed
|
||||||
|
total += n;
|
||||||
|
}
|
||||||
|
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Fix the wonky behaviour when server quit/exit/stop/close
|
// TODO: Fix the wonky behaviour when server quit/exit/stop/close
|
||||||
// command is issued. Client should close gracefully without errors.
|
// command is issued. Client should close gracefully without errors.
|
||||||
|
|||||||
Reference in New Issue
Block a user