Read from a socket Connection.
More...
|
| static int | tls_socket_read (struct Connection *conn, char *buf, size_t count) |
| | Read data from a TLS socket - Implements Connection::read() -.
|
| |
| static int | ssl_socket_read (struct Connection *conn, char *buf, size_t count) |
| | Read data from an SSL socket - Implements Connection::read() -.
|
| |
| int | raw_socket_read (struct Connection *conn, char *buf, size_t count) |
| | Read data from a socket - Implements Connection::read() -.
|
| |
| static int | mutt_sasl_conn_read (struct Connection *conn, char *buf, size_t count) |
| | Read data from an SASL connection - Implements Connection::read() -.
|
| |
| static int | tunnel_socket_read (struct Connection *conn, char *buf, size_t count) |
| | Read data from a tunnel socket - Implements Connection::read() -.
|
| |
| static int | zstrm_read (struct Connection *conn, char *buf, size_t len) |
| | Read compressed data from a socket - Implements Connection::read() -.
|
| |
Read from a socket Connection.
- Parameters
-
| conn | Connection to a server |
| buf | Buffer to store the data |
| count | Number of bytes to read |
- Return values
-
| >0 | Success, number of bytes read |
| -1 | Error, see errno |
◆ tls_socket_read()
| static int tls_socket_read |
( |
struct Connection * | conn, |
|
|
char * | buf, |
|
|
size_t | count ) |
|
static |
Read data from a TLS socket - Implements Connection::read() -.
Definition at line 1060 of file gnutls.c.
1061{
1063 if (!data)
1064 {
1066 return -1;
1067 }
1068
1069 int rc;
1070 do
1071 {
1072 rc = gnutls_record_recv(data->
session, buf, count);
1073 if (rc == GNUTLS_E_AGAIN)
1074 {
1075
1077 return -1;
1078 }
1079 } while ((rc == GNUTLS_E_AGAIN) || (rc == GNUTLS_E_INTERRUPTED));
1080
1081 if (rc < 0)
1082 {
1083 mutt_error(
"tls_socket_read (%s)", gnutls_strerror(rc));
1084 return -1;
1085 }
1086
1087 return rc;
1088}
static bool tls_socket_poll_with_timeout(struct Connection *conn)
Poll a socket with configured timeout.
void * sockdata
Backend-specific socket data.
gnutls_session_t session
GNUTLS session.
◆ ssl_socket_read()
| static int ssl_socket_read |
( |
struct Connection * | conn, |
|
|
char * | buf, |
|
|
size_t | count ) |
|
static |
Read data from an SSL socket - Implements Connection::read() -.
Definition at line 1330 of file openssl.c.
1331{
1332 struct SslSockData *data =
sockdata(conn);
1333 int rc;
1334
1335retry:
1336 rc = SSL_read(data->ssl, buf, count);
1337 if (rc > 0)
1338 return rc;
1339
1340
1341 if (
SigInt && (errno == EINTR))
1342 {
1343 rc = -1;
1344 }
1345 else if (BIO_should_retry(SSL_get_rbio(data->ssl)))
1346 {
1347
1349 {
1350 goto retry;
1351 }
1352 }
1353
1354 data->isopen = 0;
1356 return rc;
1357}
int raw_socket_poll(struct Connection *conn, time_t wait_secs)
Check if any data is waiting on a socket - Implements Connection::poll() -.
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_read()
| int raw_socket_read |
( |
struct Connection * | conn, |
|
|
char * | buf, |
|
|
size_t | count ) |
Read data from a socket - Implements Connection::read() -.
Definition at line 295 of file raw.c.
296{
297 int rc;
298
300 do
301 {
302 rc = read(conn->
fd, buf, count);
303 } while (rc < 0 && (errno == EINTR));
304
305 if (rc < 0)
306 {
309 }
311
313 {
316 rc = -1;
317 }
318
319 return rc;
320}
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_read()
| static int mutt_sasl_conn_read |
( |
struct Connection * | conn, |
|
|
char * | buf, |
|
|
size_t | count ) |
|
static |
Read data from an SASL connection - Implements Connection::read() -.
Definition at line 463 of file sasl.c.
464{
465 int rc;
466 unsigned int olen;
467
469
470
471 if (sasldata->
blen > sasldata->
bpos)
472 {
473 olen = ((sasldata->
blen - sasldata->
bpos) > count) ?
474 count :
476
477 memcpy(
buf, sasldata->
buf + sasldata->
bpos, olen);
478 sasldata->
bpos += olen;
479
480 return olen;
481 }
482
484
487
488
489 if (*sasldata->
ssf != 0)
490 {
491 do
492 {
493
494 rc = sasldata->
read(conn,
buf, count);
495 if (rc <= 0)
496 goto out;
497
499 if (rc != SASL_OK)
500 {
502 goto out;
503 }
504 }
while (sasldata->
blen == 0);
505
506 olen = ((sasldata->
blen - sasldata->
bpos) > count) ?
507 count :
509
510 memcpy(
buf, sasldata->
buf, olen);
511 sasldata->
bpos += olen;
512
513 rc = olen;
514 }
515 else
516 {
517 rc = sasldata->
read(conn,
buf, count);
518 }
519
520out:
522
523 return rc;
524}
int(* read)(struct Connection *conn, char *buf, size_t count)
Read from a socket Connection - Implements Connection::read() -.
#define mutt_debug(LEVEL,...)
@ LL_DEBUG1
Log at debug level 1.
SASL authentication API -.
void * sockdata
Underlying socket data.
unsigned int blen
Size of the read buffer.
unsigned int bpos
Current read position.
const sasl_ssf_t * ssf
Security strength factor, in bits.
const char * buf
Buffer for data read from the connection.
sasl_conn_t * saslconn
Raw SASL connection.
◆ tunnel_socket_read()
| static int tunnel_socket_read |
( |
struct Connection * | conn, |
|
|
char * | buf, |
|
|
size_t | count ) |
|
static |
Read data from a tunnel socket - Implements Connection::read() -.
Definition at line 146 of file tunnel.c.
147{
149 int rc;
150
151 do
152 {
153 rc = read(tunnel->
fd_read, buf, count);
154 } while (rc < 0 && errno == EINTR);
155
156 if (rc < 0)
157 {
159 return -1;
160 }
161
162 return rc;
163}
A network tunnel (pair of sockets)
int fd_read
File descriptor to read from.
◆ zstrm_read()
| static int zstrm_read |
( |
struct Connection * | conn, |
|
|
char * | buf, |
|
|
size_t | len ) |
|
static |
Read compressed data from a socket - Implements Connection::read() -.
Definition at line 138 of file zstrm.c.
139{
141 int rc = 0;
142 int zrc = 0;
143
144retry:
146 return 0;
147
148
149
150
152 {
155 if (rc < 0)
156 return rc;
157 else if (rc == 0)
159 else
161 }
162
165 zctx->
read.
z.avail_out = (uInt) len;
166 zctx->
read.
z.next_out = (Bytef *) buf;
167
168 zrc = inflate(&zctx->
read.
z, Z_SYNC_FLUSH);
171 len - zctx->
read.
z.avail_out, len);
172
173
175 {
178 }
179
180 switch (zrc)
181 {
182 case Z_OK:
183 zrc = len - zctx->
read.
z.avail_out;
184 if (zrc == 0)
185 {
186
188 goto retry;
189 }
190 break;
191
192 case Z_STREAM_END:
194 zrc = len - zctx->
read.
z.avail_out;
196 break;
197
198 case Z_BUF_ERROR:
200 {
202 goto retry;
203 }
204 zrc = 0;
205 break;
206
207 default:
208
210 zrc = -1;
211 break;
212 }
213
214 return zrc;
215}
@ LL_DEBUG5
Log at debug level 5.
int(* read)(struct Connection *conn, char *buf, size_t count)
struct ZstrmDirection read
Data being read and de-compressed.
struct Connection next_conn
Underlying stream.
unsigned int pos
Current position.
bool conn_eof
Connection end-of-file reached.
unsigned int len
Length of data.
z_stream z
zlib compression handle
char * buf
Buffer for data being (de-)compressed.
bool stream_eof
Stream end-of-file reached.
◆ read
| int(* SaslSockData::read) (struct Connection *conn, char *buf, size_t count) |