NeoMutt  2024-03-23-147-g885fbc
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches

Check whether a socket read would block. More...

+ Collaboration diagram for poll():

Functions

static int tls_socket_poll (struct Connection *conn, time_t wait_secs)
 Check if any data is waiting on a socket - Implements Connection::poll() -.
 
static int ssl_socket_poll (struct Connection *conn, time_t wait_secs)
 Check if any data is waiting on a socket - Implements Connection::poll() -.
 
int raw_socket_poll (struct Connection *conn, time_t wait_secs)
 Check if any data is waiting on a socket - Implements Connection::poll() -.
 
static int mutt_sasl_conn_poll (struct Connection *conn, time_t wait_secs)
 Check if any data is waiting on a socket - Implements Connection::poll() -.
 
static int tunnel_socket_poll (struct Connection *conn, time_t wait_secs)
 Check if any data is waiting on a socket - Implements Connection::poll() -.
 
static int zstrm_poll (struct Connection *conn, time_t wait_secs)
 Check if any data is waiting on a socket - Implements Connection::poll() -.
 

Variables

int(* SaslSockData::poll )(struct Connection *conn, time_t wait_secs)
 Check if any data is waiting on a socket - Implements Connection::poll() -.
 

Detailed Description

Check whether a socket read would block.

Parameters
connConnection to a server
wait_secsHow long to wait for a response
Return values
>0There is data to read
0Read would block
-1Connection doesn't support polling

Function Documentation

◆ tls_socket_poll()

static int tls_socket_poll ( struct Connection conn,
time_t  wait_secs 
)
static

Check if any data is waiting on a socket - Implements Connection::poll() -.

Definition at line 994 of file gnutls.c.

995{
996 struct TlsSockData *data = conn->sockdata;
997 if (!data)
998 return -1;
999
1000 if (gnutls_record_check_pending(data->session))
1001 return 1;
1002
1003 return raw_socket_poll(conn, wait_secs);
1004}
int raw_socket_poll(struct Connection *conn, time_t wait_secs)
Check if any data is waiting on a socket - Implements Connection::poll() -.
Definition: raw.c:353
void * sockdata
Backend-specific socket data.
Definition: connection.h:55
TLS socket data -.
Definition: gnutls.c:82
gnutls_session_t session
Definition: gnutls.c:83
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ssl_socket_poll()

static int ssl_socket_poll ( struct Connection conn,
time_t  wait_secs 
)
static

Check if any data is waiting on a socket - Implements Connection::poll() -.

Definition at line 1313 of file openssl.c.

1314{
1315 if (!conn)
1316 return -1;
1317
1318 if (SSL_has_pending(sockdata(conn)->ssl))
1319 return 1;
1320
1321 return raw_socket_poll(conn, wait_secs);
1322}
static struct SslSockData * sockdata(struct Connection *conn)
Get a Connection's socket data.
Definition: openssl.c:1199
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ raw_socket_poll()

int raw_socket_poll ( struct Connection conn,
time_t  wait_secs 
)

Check if any data is waiting on a socket - Implements Connection::poll() -.

Definition at line 353 of file raw.c.

354{
355 if (conn->fd < 0)
356 return -1;
357
358 fd_set rfds = { 0 };
359 struct timeval tv = { 0 };
360
361 uint64_t wait_millis = wait_secs * 1000UL;
362
363 while (true)
364 {
365 tv.tv_sec = wait_millis / 1000;
366 tv.tv_usec = (wait_millis % 1000) * 1000;
367
368 FD_ZERO(&rfds);
369 FD_SET(conn->fd, &rfds);
370
371 uint64_t pre_t = mutt_date_now_ms();
372 const int rc = select(conn->fd + 1, &rfds, NULL, NULL, &tv);
373 uint64_t post_t = mutt_date_now_ms();
374
375 if ((rc > 0) || ((rc < 0) && (errno != EINTR)))
376 return rc;
377
378 if (SigInt)
380
381 wait_millis += pre_t;
382 if (wait_millis <= post_t)
383 return 0;
384 wait_millis -= post_t;
385 }
386}
void mutt_query_exit(void)
Ask the user if they want to leave NeoMutt.
Definition: curs_lib.c:137
uint64_t mutt_date_now_ms(void)
Return the number of milliseconds since the Unix epoch.
Definition: date.c:464
volatile sig_atomic_t SigInt
true after SIGINT is received
Definition: signal.c:63
int fd
Socket file descriptor.
Definition: connection.h:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_sasl_conn_poll()

static int mutt_sasl_conn_poll ( struct Connection conn,
time_t  wait_secs 
)
static

Check if any data is waiting on a socket - Implements Connection::poll() -.

Definition at line 584 of file sasl.c.

585{
586 struct SaslSockData *sasldata = conn->sockdata;
587 int rc;
588
589 conn->sockdata = sasldata->sockdata;
590 rc = sasldata->poll(conn, wait_secs);
591 conn->sockdata = sasldata;
592
593 return rc;
594}
int(* poll)(struct Connection *conn, time_t wait_secs)
Check if any data is waiting on a socket - Implements Connection::poll() -.
Definition: sasl.c:95
SASL authentication API -.
Definition: sasl.c:65
void * sockdata
Underlying socket data.
Definition: sasl.c:75
+ Here is the caller graph for this function:

◆ tunnel_socket_poll()

static int tunnel_socket_poll ( struct Connection conn,
time_t  wait_secs 
)
static

Check if any data is waiting on a socket - Implements Connection::poll() -.

Definition at line 196 of file tunnel.c.

197{
198 struct TunnelSockData *tunnel = conn->sockdata;
199 int ofd;
200 int rc;
201
202 ofd = conn->fd;
203 conn->fd = tunnel->fd_read;
204 rc = raw_socket_poll(conn, wait_secs);
205 conn->fd = ofd;
206
207 return rc;
208}
A network tunnel (pair of sockets)
Definition: tunnel.c:50
int fd_read
File descriptor to read from.
Definition: tunnel.c:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ zstrm_poll()

static int zstrm_poll ( struct Connection conn,
time_t  wait_secs 
)
static

Check if any data is waiting on a socket - Implements Connection::poll() -.

Definition at line 214 of file zstrm.c.

215{
216 struct ZstrmContext *zctx = conn->sockdata;
217
218 mutt_debug(LL_DEBUG5, "%s\n",
219 (zctx->read.z.avail_out == 0) || (zctx->read.pos > 0) ?
220 "last read wrote full buffer" :
221 "falling back on next stream");
222 if ((zctx->read.z.avail_out == 0) || (zctx->read.pos > 0))
223 return 1;
224
225 return zctx->next_conn.poll(&zctx->next_conn, wait_secs);
226}
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
int(* poll)(struct Connection *conn, time_t wait_secs)
Definition: connection.h:105
Data compression layer.
Definition: zstrm.c:58
struct ZstrmDirection read
Data being read and de-compressed.
Definition: zstrm.c:59
struct Connection next_conn
Underlying stream.
Definition: zstrm.c:61
unsigned int pos
Current position.
Definition: zstrm.c:49
z_stream z
zlib compression handle
Definition: zstrm.c:46
+ Here is the caller graph for this function:

Variable Documentation

◆ poll

int(* SaslSockData::poll) (struct Connection *conn, time_t wait_secs)

Check if any data is waiting on a socket - Implements Connection::poll() -.

Definition at line 95 of file sasl.c.