NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN

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 whether a socket read would block - Implements Connection::poll() -. More...
 
static int ssl_socket_poll (struct Connection *conn, time_t wait_secs)
 Check whether a socket read would block - Implements Connection::poll() -. More...
 
int raw_socket_poll (struct Connection *conn, time_t wait_secs)
 Checks whether reads would block - Implements Connection::poll() -. More...
 
static int mutt_sasl_conn_poll (struct Connection *conn, time_t wait_secs)
 Check an SASL connection for data - Implements Connection::poll() -. More...
 
static int tunnel_socket_poll (struct Connection *conn, time_t wait_secs)
 Checks whether tunnel reads would block - Implements Connection::poll() -. More...
 
static int zstrm_poll (struct Connection *conn, time_t wait_secs)
 Checks whether reads would block - Implements Connection::poll() -. More...
 

Variables

int(* SaslSockData::poll )(struct Connection *conn, time_t wait_secs)
 Check whether a socket read would block - Implements Connection::poll() -. More...
 

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 whether a socket read would block - Implements Connection::poll() -.

Definition at line 1010 of file gnutls.c.

1011 {
1012  struct TlsSockData *data = conn->sockdata;
1013  if (!data)
1014  return -1;
1015 
1016  if (gnutls_record_check_pending(data->state))
1017  return 1;
1018 
1019  return raw_socket_poll(conn, wait_secs);
1020 }
void * sockdata
Backend-specific socket data.
Definition: connection.h:46
gnutls_session_t state
Definition: gnutls.c:81
TLS socket data -.
Definition: gnutls.c:79
int raw_socket_poll(struct Connection *conn, time_t wait_secs)
Checks whether reads would block - Implements Connection::poll() -.
Definition: raw.c:327
+ 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 whether a socket read would block - Implements Connection::poll() -.

Definition at line 1318 of file openssl.c.

1319 {
1320  if (!conn)
1321  return -1;
1322 
1323  if (SSL_has_pending(sockdata(conn)->ssl))
1324  return 1;
1325 
1326  return raw_socket_poll(conn, wait_secs);
1327 }
static struct SslSockData * sockdata(struct Connection *conn)
Get a Connection's socket data.
Definition: openssl.c:1198
int raw_socket_poll(struct Connection *conn, time_t wait_secs)
Checks whether reads would block - Implements Connection::poll() -.
Definition: raw.c:327
+ 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 
)

Checks whether reads would block - Implements Connection::poll() -.

Definition at line 327 of file raw.c.

328 {
329  if (conn->fd < 0)
330  return -1;
331 
332  fd_set rfds;
333  struct timeval tv;
334 
335  uint64_t wait_millis = wait_secs * 1000UL;
336 
337  while (true)
338  {
339  tv.tv_sec = wait_millis / 1000;
340  tv.tv_usec = (wait_millis % 1000) * 1000;
341 
342  FD_ZERO(&rfds);
343  FD_SET(conn->fd, &rfds);
344 
345  uint64_t pre_t = mutt_date_epoch_ms();
346  const int rc = select(conn->fd + 1, &rfds, NULL, NULL, &tv);
347  uint64_t post_t = mutt_date_epoch_ms();
348 
349  if ((rc > 0) || ((rc < 0) && (errno != EINTR)))
350  return rc;
351 
352  if (SigInt)
353  mutt_query_exit();
354 
355  wait_millis += pre_t;
356  if (wait_millis <= post_t)
357  return 0;
358  wait_millis -= post_t;
359  }
360 }
uint64_t mutt_date_epoch_ms(void)
Return the number of milliseconds since the Unix epoch.
Definition: date.c:436
WHERE SIG_ATOMIC_VOLATILE_T SigInt
true after SIGINT is received
Definition: mutt_globals.h:67
void mutt_query_exit(void)
Ask the user if they want to leave NeoMutt.
Definition: curs_lib.c:403
int fd
Socket file descriptor.
Definition: connection.h:44
+ 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 an SASL connection for data - Implements Connection::poll() -.

Definition at line 581 of file sasl.c.

582 {
583  struct SaslSockData *sasldata = conn->sockdata;
584  int rc;
585 
586  conn->sockdata = sasldata->sockdata;
587  rc = sasldata->poll(conn, wait_secs);
588  conn->sockdata = sasldata;
589 
590  return rc;
591 }
SASL authentication API -.
Definition: sasl.c:60
void * sockdata
Backend-specific socket data.
Definition: connection.h:46
void * sockdata
Underlying socket data.
Definition: sasl.c:71
int(* poll)(struct Connection *conn, time_t wait_secs)
Check whether a socket read would block - Implements Connection::poll() -.
Definition: sasl.c:91
+ Here is the caller graph for this function:

◆ tunnel_socket_poll()

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

Checks whether tunnel reads would block - Implements Connection::poll() -.

Definition at line 187 of file tunnel.c.

188 {
189  struct TunnelSockData *tunnel = conn->sockdata;
190  int ofd;
191  int rc;
192 
193  ofd = conn->fd;
194  conn->fd = tunnel->fd_read;
195  rc = raw_socket_poll(conn, wait_secs);
196  conn->fd = ofd;
197 
198  return rc;
199 }
int fd_read
File descriptor to read from.
Definition: tunnel.c:50
void * sockdata
Backend-specific socket data.
Definition: connection.h:46
A network tunnel (pair of sockets)
Definition: tunnel.c:47
int fd
Socket file descriptor.
Definition: connection.h:44
int raw_socket_poll(struct Connection *conn, time_t wait_secs)
Checks whether reads would block - Implements Connection::poll() -.
Definition: raw.c:327
+ 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

Checks whether reads would block - Implements Connection::poll() -.

Definition at line 211 of file zstrm.c.

212 {
213  struct ZstrmContext *zctx = conn->sockdata;
214 
215  mutt_debug(LL_DEBUG5, "%s\n",
216  (zctx->read.z.avail_out == 0) || (zctx->read.pos > 0) ?
217  "last read wrote full buffer" :
218  "falling back on next stream");
219  if ((zctx->read.z.avail_out == 0) || (zctx->read.pos > 0))
220  return 1;
221 
222  return zctx->next_conn.poll(&zctx->next_conn, wait_secs);
223 }
Data compression layer.
Definition: zstrm.c:54
void * sockdata
Backend-specific socket data.
Definition: connection.h:46
struct Connection next_conn
Underlying stream.
Definition: zstrm.c:58
struct ZstrmDirection read
Data being read and de-compressed.
Definition: zstrm.c:56
unsigned int pos
Current position.
Definition: zstrm.c:46
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
int(* poll)(struct Connection *conn, time_t wait_secs)
Definition: connection.h:108
z_stream z
zlib compression handle
Definition: zstrm.c:43
Log at debug level 5.
Definition: logging.h:44
+ Here is the caller graph for this function:

Variable Documentation

◆ poll

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

Check whether a socket read would block - Implements Connection::poll() -.

Definition at line 91 of file sasl.c.