Write to a socket Connection.
More...
|
static int | tls_socket_write (struct Connection *conn, const char *buf, size_t count) |
| Write data to a TLS socket - Implements Connection::write() -.
|
|
static int | ssl_socket_write (struct Connection *conn, const char *buf, size_t count) |
| Write data to an SSL socket - Implements Connection::write() -.
|
|
int | raw_socket_write (struct Connection *conn, const char *buf, size_t count) |
| Write data to a socket - Implements Connection::write() -.
|
|
static int | mutt_sasl_conn_write (struct Connection *conn, const char *buf, size_t count) |
| Write to an SASL connection - Implements Connection::write() -.
|
|
static int | tunnel_socket_write (struct Connection *conn, const char *buf, size_t count) |
| Write data to a tunnel socket - Implements Connection::write() -.
|
|
static int | zstrm_write (struct Connection *conn, const char *buf, size_t count) |
| Write compressed data to a socket - Implements Connection::write() -.
|
|
Write to a socket Connection.
- Parameters
-
- Return values
-
>0 | Success, number of bytes written |
-1 | Error, see errno |
◆ tls_socket_write()
static int tls_socket_write |
( |
struct Connection * |
conn, |
|
|
const char * |
buf, |
|
|
size_t |
count |
|
) |
| |
|
static |
Write data to a TLS socket - Implements Connection::write() -.
Definition at line 1071 of file gnutls.c.
1072{
1074 size_t sent = 0;
1075
1076 if (!data)
1077 {
1079 return -1;
1080 }
1081
1082 do
1083 {
1084 int rc;
1085 do
1086 {
1087 rc = gnutls_record_send(data->
session, buf + sent, count - sent);
1088 } while ((rc == GNUTLS_E_AGAIN) || (rc == GNUTLS_E_INTERRUPTED));
1089
1090 if (rc < 0)
1091 {
1092 mutt_error(
"tls_socket_write (%s)", gnutls_strerror(rc));
1093 return -1;
1094 }
1095
1096 sent += rc;
1097 } while (sent < count);
1098
1099 return sent;
1100}
void * sockdata
Backend-specific socket data.
◆ ssl_socket_write()
static int ssl_socket_write |
( |
struct Connection * |
conn, |
|
|
const char * |
buf, |
|
|
size_t |
count |
|
) |
| |
|
static |
Write data to an SSL socket - Implements Connection::write() -.
Definition at line 1361 of file openssl.c.
1362{
1363 if (!conn || !conn->
sockdata || !buf || (count == 0))
1364 return -1;
1365
1366 struct SslSockData *data =
sockdata(conn);
1367 int rc;
1368
1369retry:
1370 rc = SSL_write(data->ssl, buf, count);
1371 if (rc > 0)
1372 return rc;
1373
1374
1375 if (
SigInt && (errno == EINTR))
1376 {
1377 rc = -1;
1378 }
1379 else if (BIO_should_retry(SSL_get_wbio(data->ssl)))
1380 {
1381
1382 goto retry;
1383 }
1384
1386 return rc;
1387}
SIG_ATOMIC_VOLATILE_T SigInt
true after SIGINT is received
static struct SslSockData * sockdata(struct Connection *conn)
Get a Connection's socket data.
static void ssl_err(struct SslSockData *data, int err)
Display an SSL error message.
◆ raw_socket_write()
int raw_socket_write |
( |
struct Connection * |
conn, |
|
|
const char * |
buf, |
|
|
size_t |
count |
|
) |
| |
Write data to a socket - Implements Connection::write() -.
Definition at line 307 of file raw.c.
308{
309 int rc;
310 size_t sent = 0;
311
313 do
314 {
315 do
316 {
317 rc = write(conn->
fd, buf + sent, count - sent);
318 } while (rc < 0 && (errno == EINTR));
319
320 if (rc < 0)
321 {
324 return -1;
325 }
326
327 sent += rc;
328 }
while ((sent < count) && !
SigInt);
329
331 return sent;
332}
void mutt_sig_allow_interrupt(bool allow)
Allow/disallow Ctrl-C (SIGINT)
char host[128]
Server to login to.
struct ConnAccount account
Account details: username, password, etc.
int fd
Socket file descriptor.
◆ mutt_sasl_conn_write()
static int mutt_sasl_conn_write |
( |
struct Connection * |
conn, |
|
|
const char * |
buf, |
|
|
size_t |
count |
|
) |
| |
|
static |
Write to an SASL connection - Implements Connection::write() -.
Definition at line 533 of file sasl.c.
534{
535 int rc;
536 const char *pbuf = NULL;
537 unsigned int olen, plen;
538
541
542
543 if (*sasldata->
ssf != 0)
544 {
545
546 do
547 {
549
550 rc = sasl_encode(sasldata->
saslconn,
buf, olen, &pbuf, &plen);
551 if (rc != SASL_OK)
552 {
554 goto fail;
555 }
556
557 rc = sasldata->
write(conn, pbuf, plen);
558 if (rc != plen)
559 goto fail;
560
561 count -= olen;
563 }
while (count > *sasldata->
pbufsize);
564 }
565 else
566 {
567
568 rc = sasldata->
write(conn,
buf, count);
569 }
570
572
573 return rc;
574
575fail:
577 return -1;
578}
int(* write)(struct Connection *conn, const char *buf, size_t count)
Write to a socket Connection - Implements Connection::write() -.
#define mutt_debug(LEVEL,...)
@ LL_DEBUG1
Log at debug level 1.
SASL authentication API -.
void * sockdata
Underlying socket data.
const unsigned int * pbufsize
const char * buf
Buffer for data read from the connection.
◆ tunnel_socket_write()
static int tunnel_socket_write |
( |
struct Connection * |
conn, |
|
|
const char * |
buf, |
|
|
size_t |
count |
|
) |
| |
|
static |
Write data to a tunnel socket - Implements Connection::write() -.
Definition at line 167 of file tunnel.c.
168{
170 int rc;
171 size_t sent = 0;
172
173 do
174 {
175 do
176 {
177 rc = write(tunnel->
fd_write, buf + sent, count - sent);
178 } while (rc < 0 && errno == EINTR);
179
180 if (rc < 0)
181 {
183 return -1;
184 }
185
186 sent += rc;
187 } while (sent < count);
188
189 return sent;
190}
A network tunnel (pair of sockets)
int fd_write
File descriptor to write to.
◆ zstrm_write()
static int zstrm_write |
( |
struct Connection * |
conn, |
|
|
const char * |
buf, |
|
|
size_t |
count |
|
) |
| |
|
static |
Write compressed data to a socket - Implements Connection::write() -.
Definition at line 228 of file zstrm.c.
229{
231 int rc;
232
233 zctx->
write.
z.avail_in = (uInt) count;
234 zctx->
write.
z.next_in = (Bytef *) buf;
237
238 do
239 {
240 int zrc = deflate(&zctx->
write.
z, Z_PARTIAL_FLUSH);
241 if (zrc == Z_OK)
242 {
243
247 count - zctx->
write.
z.avail_in, count);
249 {
252 if (rc < 0)
253 return -1;
254
255 wbufp += rc;
257 }
258
259
260
261
262 if ((zctx->
write.
z.avail_out != 0) && (zctx->
write.
z.avail_in == 0))
263 break;
264
267 }
268 else
269 {
270
271
272 return -1;
273 }
274 } while (true);
275
276 rc = (int) count;
277 return (rc <= 0) ? 1 : rc;
278}
@ LL_DEBUG5
Log at debug level 5.
int(* write)(struct Connection *conn, const char *buf, size_t count)
struct ZstrmDirection write
Data being compressed and written.
struct Connection next_conn
Underlying stream.
unsigned int pos
Current position.
unsigned int len
Length of data.
z_stream z
zlib compression handle
char * buf
Buffer for data being (de-)compressed.
◆ write
int(* SaslSockData::write) (struct Connection *conn, const char *buf, size_t count) |