| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "s2n.h" |
| 17 |
|
| 18 |
int s2n_example_send(struct s2n_connection *conn, uint8_t *data, size_t data_size) |
| 19 |
{ |
| 20 |
s2n_blocked_status blocked = S2N_NOT_BLOCKED; |
| 21 |
int bytes_written = 0; |
| 22 |
while (bytes_written < data_size) { |
| 23 |
int w = s2n_send(conn, data + bytes_written, data_size - bytes_written, &blocked); |
| 24 |
if (w >= 0) { |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
bytes_written += w; |
| 29 |
} else if (s2n_error_get_type(s2n_errno) == S2N_ERR_T_BLOCKED) { |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
continue; |
| 39 |
} else { |
| 40 |
|
| 41 |
fprintf(stderr, "Error: %s. %s\n", s2n_strerror(s2n_errno, NULL), s2n_strerror_debug(s2n_errno, NULL)); |
| 42 |
return -1; |
| 43 |
} |
| 44 |
} |
| 45 |
return 0; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
#ifndef _WIN32 |
| 50 |
int s2n_example_sendv(struct s2n_connection *conn, uint8_t *data, size_t data_size) |
| 51 |
{ |
| 52 |
struct iovec iov[1] = { 0 }; |
| 53 |
iov[0].iov_base = data; |
| 54 |
iov[0].iov_len = data_size; |
| 55 |
|
| 56 |
s2n_blocked_status blocked = S2N_NOT_BLOCKED; |
| 57 |
int bytes_written = 0; |
| 58 |
while (bytes_written < data_size) { |
| 59 |
int w = s2n_sendv_with_offset(conn, iov, 1, bytes_written, &blocked); |
| 60 |
if (w >= 0) { |
| 61 |
bytes_written += w; |
| 62 |
} else if (s2n_error_get_type(s2n_errno) != S2N_ERR_T_BLOCKED) { |
| 63 |
fprintf(stderr, "Error: %s. %s\n", s2n_strerror(s2n_errno, NULL), s2n_strerror_debug(s2n_errno, NULL)); |
| 64 |
return -1; |
| 65 |
} |
| 66 |
} |
| 67 |
return 0; |
| 68 |
} |
| 69 |
#endif |