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 1073 of file gnutls.c.
1074{
1076 size_t sent = 0;
1077
1078 if (!data)
1079 {
1081 return -1;
1082 }
1083
1084 do
1085 {
1086 int rc;
1087 do
1088 {
1089 rc = gnutls_record_send(data->
session, buf + sent, count - sent);
1090 } while ((rc == GNUTLS_E_AGAIN) || (rc == GNUTLS_E_INTERRUPTED));
1091
1092 if (rc < 0)
1093 {
1094 mutt_error(
"tls_socket_write (%s)", gnutls_strerror(rc));
1095 return -1;
1096 }
1097
1098 sent += rc;
1099 } while (sent < count);
1100
1101 return sent;
1102}
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 1366 of file openssl.c.
1367{
1368 if (!conn || !conn->
sockdata || !buf || (count == 0))
1369 return -1;
1370
1371 struct SslSockData *data =
sockdata(conn);
1372 int rc;
1373
1374retry:
1375 rc = SSL_write(data->ssl, buf, count);
1376 if (rc > 0)
1377 return rc;
1378
1379
1380 if (
SigInt && (errno == EINTR))
1381 {
1382 rc = -1;
1383 }
1384 else if (BIO_should_retry(SSL_get_wbio(data->ssl)))
1385 {
1386
1387 goto retry;
1388 }
1389
1391 return rc;
1392}
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.
volatile sig_atomic_t SigInt
true after SIGINT is received
◆ 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 325 of file raw.c.
326{
327 int rc;
328 size_t sent = 0;
329
331 do
332 {
333 do
334 {
335 rc = write(conn->
fd, buf + sent, count - sent);
336 } while (rc < 0 && (errno == EINTR));
337
338 if (rc < 0)
339 {
342 return -1;
343 }
344
345 sent += rc;
346 }
while ((sent < count) && !
SigInt);
347
349 return sent;
350}
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 534 of file sasl.c.
535{
536 int rc;
537 const char *pbuf = NULL;
538 unsigned int olen, plen;
539
542
543
544 if (*sasldata->
ssf != 0)
545 {
546
547 do
548 {
550
551 rc = sasl_encode(sasldata->
saslconn,
buf, olen, &pbuf, &plen);
552 if (rc != SASL_OK)
553 {
555 goto fail;
556 }
557
558 rc = sasldata->
write(conn, pbuf, plen);
559 if (rc != plen)
560 goto fail;
561
562 count -= olen;
564 }
while (count > *sasldata->
pbufsize);
565 }
566 else
567 {
568
569 rc = sasldata->
write(conn,
buf, count);
570 }
571
573
574 return rc;
575
576fail:
578 return -1;
579}
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 168 of file tunnel.c.
169{
171 int rc;
172 size_t sent = 0;
173
174 do
175 {
176 do
177 {
178 rc = write(tunnel->
fd_write, buf + sent, count - sent);
179 } while (rc < 0 && errno == EINTR);
180
181 if (rc < 0)
182 {
184 return -1;
185 }
186
187 sent += rc;
188 } while (sent < count);
189
190 return sent;
191}
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 231 of file zstrm.c.
232{
234 int rc;
235
236 zctx->
write.
z.avail_in = (uInt) count;
237 zctx->
write.
z.next_in = (Bytef *) buf;
240
241 do
242 {
243 int zrc = deflate(&zctx->
write.
z, Z_PARTIAL_FLUSH);
244 if (zrc == Z_OK)
245 {
246
250 count - zctx->
write.
z.avail_in, count);
252 {
255 if (rc < 0)
256 return -1;
257
258 wbufp += rc;
260 }
261
262
263
264
265 if ((zctx->
write.
z.avail_out != 0) && (zctx->
write.
z.avail_in == 0))
266 break;
267
270 }
271 else
272 {
273
274
275 return -1;
276 }
277 } while (true);
278
279 rc = (int) count;
280 return (rc <= 0) ? 1 : rc;
281}
@ 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) |