mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2025-04-18 05:38:36 +01:00
Implement TCPSocketSendAll and TCPSocketSendString.
Update TCP Chat client and server programs to use new methods.
This commit is contained in:
parent
239a5cdf87
commit
3fa559706f
4 changed files with 31 additions and 5 deletions
Binary file not shown.
|
@ -27,7 +27,7 @@ U0 ChatMessageTask(I64)
|
|||
DocPrint(chat_display_task->put_doc,
|
||||
"$$BG,BLUE$$$$BLACK$$<local>$$FG$$$$BG$$ %s\n", message);
|
||||
|
||||
TCPSocketSend(tcp, message, StrLen(message));
|
||||
TCPSocketSendString(tcp, message);
|
||||
|
||||
DocClear;
|
||||
DocPrint(, "$$WW,1$$");
|
||||
|
|
|
@ -55,7 +55,7 @@ U0 ChatServerBroadcast(CTCPSocket *tcp_socket, I64 length)
|
|||
|
||||
message = MStrPrint(message_prefix, buffer);
|
||||
|
||||
TCPSocketSend(dest_socket, message, StrLen(message));
|
||||
TCPSocketSendString(dest_socket, message);
|
||||
|
||||
Free(message);
|
||||
Free(message_prefix);
|
||||
|
@ -79,7 +79,7 @@ U0 ChatServerBroadcastDisconnect()
|
|||
{
|
||||
conn_socket = conn->socket;
|
||||
|
||||
TCPSocketSend(conn_socket, message, StrLen(message));
|
||||
TCPSocketSendString(conn_socket, message);
|
||||
|
||||
conn = conn->next;
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ U0 ChatServer()
|
|||
|
||||
join_msg = MStrPrint("$$BG,LTGRAY$$$$DKGRAY$$Connected clients: %d$$FG$$$$BG$$", QueueCount(connections) + 1);
|
||||
|
||||
TCPSocketSend(new_socket, join_msg, StrLen(join_msg));
|
||||
TCPSocketSendString(new_socket, join_msg);
|
||||
Free(join_msg);
|
||||
|
||||
join_msg = MStrPrint("$$BG,LTGRAY$$$$DKGRAY$$New connection. Connected clients: %d$$FG$$$$BG$$",
|
||||
|
@ -207,7 +207,7 @@ U0 ChatServer()
|
|||
{
|
||||
"\nNotifying clients of new connection.\n";
|
||||
conn_socket = conn->socket;
|
||||
TCPSocketSend(conn_socket, join_msg, StrLen(join_msg));
|
||||
TCPSocketSendString(conn_socket, join_msg);
|
||||
conn = conn->next;
|
||||
}
|
||||
Free(join_msg);
|
||||
|
|
|
@ -1372,6 +1372,32 @@ I64 TCPSocketSend(CTCPSocket *tcp_socket, U8 *buffer, I64 length)
|
|||
return sent_total;
|
||||
}
|
||||
|
||||
I64 TCPSocketSendAll(CTCPSocket *tcp_socket, U8 *buffer, I64 length)
|
||||
{
|
||||
I64 total = 0;
|
||||
I64 sent = 0;
|
||||
|
||||
while (length)
|
||||
{
|
||||
sent = TCPSocketSend(tcp_socket, buffer, length);
|
||||
|
||||
if (sent > 0)
|
||||
{
|
||||
buffer += sent;
|
||||
total += sent;
|
||||
length -= sent;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
I64 TCPSocketSendString(CTCPSocket *tcp_socket, U8 *string)
|
||||
{
|
||||
return TCPSocketSendAll(tcp_socket, string, StrLen(string));
|
||||
}
|
||||
|
||||
U0 TCPTreeNodeRep(CTCPTreeNode *node)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue