diff options
author | Dirk Engling <erdgeist@erdgeist.org> | 2022-05-17 16:13:17 +0200 |
---|---|---|
committer | Dirk Engling <erdgeist@erdgeist.org> | 2022-05-17 16:13:17 +0200 |
commit | ebfe3a6cb5fec435e025fa5587b1c7047a421df2 (patch) | |
tree | f5f91f72ed5335cf6632ccd511da67c394778dfe | |
parent | 1c04bbfea700a8a38719e9a30dd47b37bf609a3d (diff) |
Use a staging area to glue newlines to outgoing messages before sending them in two packets
-rw-r--r-- | vchat-connection.c | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/vchat-connection.c b/vchat-connection.c index 06ea187..60dc81f 100644 --- a/vchat-connection.c +++ b/vchat-connection.c | |||
@@ -190,31 +190,23 @@ vc_disconnect () { | |||
190 | loggedin = 0; | 190 | loggedin = 0; |
191 | } | 191 | } |
192 | 192 | ||
193 | #define STAGINGSIZE 16384 | ||
194 | static char _staging[STAGINGSIZE]; | ||
193 | void | 195 | void |
194 | vc_sendmessage (const char *msg) | 196 | vc_sendmessage (const char *msg) |
195 | { | 197 | { |
198 | size_t sent, len = snprintf(_staging, sizeof(_staging), "%s\r\n", msg); | ||
196 | #ifdef DEBUG | 199 | #ifdef DEBUG |
197 | /* debugging? log network output! */ | 200 | /* debugging? log network output! */ |
198 | fprintf (dumpfile, ">| %s (%zd)\n", msg, strlen(msg)); | 201 | fprintf (dumpfile, ">| (%zd) %s\n", len - 2, msg); |
199 | #endif | 202 | #endif |
200 | 203 | ||
201 | if (getintoption(CF_USESSL)) { | 204 | if (getintoption(CF_USESSL)) |
202 | /* send data to server */ | 205 | sent = vc_tls_sendmessage (_staging, len); |
203 | if (vc_tls_sendmessage (msg, strlen (msg)) != strlen (msg)) | 206 | else |
204 | writecf (FS_ERR,"Message sending fuzzy."); | 207 | sent = write (serverfd, _staging, len); |
205 | 208 | if (sent != len) | |
206 | /* send line termination to server */ | 209 | writecf (FS_ERR,"Message sending fuzzy."); |
207 | if (vc_tls_sendmessage ("\r\n", 2) != 2) | ||
208 | writecf (FS_ERR,"Message sending fuzzy."); | ||
209 | } else { | ||
210 | /* send data to server */ | ||
211 | if (write (serverfd, msg, strlen (msg)) != strlen (msg)) | ||
212 | writecf (FS_ERR,"Message sending fuzzy."); | ||
213 | |||
214 | /* send line termination to server */ | ||
215 | if (write (serverfd, "\r\n", 2) != 2) | ||
216 | writecf (FS_ERR,"Message sending fuzzy."); | ||
217 | } | ||
218 | } | 210 | } |
219 | 211 | ||
220 | /* offset in buffer (for linebreaks at packet borders) */ | 212 | /* offset in buffer (for linebreaks at packet borders) */ |