Skip to content

Commit

Permalink
Fix return from kws_raw_write on fragmented frame sending (#214)
Browse files Browse the repository at this point in the history
* kws_raw_write should return the total number of bytes sent, not just the last fragment sent

* Adjustment to make sure returns of -1 are captured as well, and fix missing spot in SSL block

* Added zero to be inclusive as successful write when using raw sockets, but according to SSL lib 0 is an error so the behavior is slightly different using SSL versus not on the writing returns

* Adjust the kws_write_frame so that when it sees a return <=0 it returns the error instead of the total written bytes
  • Loading branch information
Astaelan authored Jul 16, 2024
1 parent dcddb83 commit 1769030
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/kws.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ KS_DECLARE(ks_ssize_t) kws_raw_write(kws_t *kws, void *data, ks_size_t bytes)
r = ssl_err * -1;
}

return r;
return r > 0 ? wrote : r;
}

do {
Expand Down Expand Up @@ -650,7 +650,7 @@ KS_DECLARE(ks_ssize_t) kws_raw_write(kws_t *kws, void *data, ks_size_t bytes)
//printf("wRITE FAIL: %s\n", strerror(errno));
//}

return r;
return r >= 0 ? wrote : r;
}

static void setup_socket(ks_socket_t sock)
Expand Down Expand Up @@ -1622,7 +1622,7 @@ KS_DECLARE(ks_ssize_t) kws_write_frame(kws_t *kws, kws_opcode_t oc, const void *

raw_ret = kws_raw_write(kws, bp, (hlen + bytes));

if (raw_ret != (ks_ssize_t) (hlen + bytes)) {
if (raw_ret <= 0 || raw_ret != (ks_ssize_t) (hlen + bytes)) {
return raw_ret;
}

Expand Down

0 comments on commit 1769030

Please sign in to comment.