NeoMutt  2025-12-11-694-ga89709
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches

Close a socket Connection. More...

+ Collaboration diagram for close():

Functions

static int tls_socket_close (struct Connection *conn)
 Close a TLS socket - Implements Connection::close() -.
 
static int tls_starttls_close (struct Connection *conn)
 Close a TLS connection - Implements Connection::close() -.
 
static int ssl_socket_close_and_restore (struct Connection *conn)
 Close an SSL Connection and restore Connection callbacks - Implements Connection::close() -.
 
static int ssl_socket_close (struct Connection *conn)
 Close an SSL connection - Implements Connection::close() -.
 
int raw_socket_close (struct Connection *conn)
 Close a socket - Implements Connection::close() -.
 
static int mutt_sasl_conn_close (struct Connection *conn)
 Close SASL connection - Implements Connection::close() -.
 
static int tunnel_socket_close (struct Connection *conn)
 Close a tunnel socket - Implements Connection::close() -.
 
static int zstrm_close (struct Connection *conn)
 Close a socket - Implements Connection::close() -.
 

Variables

int(* SaslSockData::close )(struct Connection *conn)
 Close a socket Connection - Implements Connection::close() -.
 

Detailed Description

Close a socket Connection.

Parameters
connConnection to a server
Return values
0Success
-1Error, see errno

Function Documentation

◆ tls_socket_close()

static int tls_socket_close ( struct Connection * conn)
static

Close a TLS socket - Implements Connection::close() -.

Definition at line 1018 of file gnutls.c.

1019{
1020 struct TlsSockData *data = conn->sockdata;
1021 if (data)
1022 {
1023 /* shut down only the write half to avoid hanging waiting for the remote to respond.
1024 *
1025 * RFC5246 7.2.1. "Closure Alerts"
1026 *
1027 * It is not required for the initiator of the close to wait for the
1028 * responding close_notify alert before closing the read side of the
1029 * connection. */
1030 gnutls_bye(data->session, GNUTLS_SHUT_WR);
1031
1032 gnutls_certificate_free_credentials(data->xcred);
1033 gnutls_deinit(data->session);
1034 FREE(&conn->sockdata);
1035 }
1036
1037 return raw_socket_close(conn);
1038}
int raw_socket_close(struct Connection *conn)
Close a socket - Implements Connection::close() -.
Definition raw.c:393
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
void * sockdata
Backend-specific socket data.
Definition connection.h:55
TLS socket data -.
Definition gnutls.c:83
gnutls_certificate_credentials_t xcred
GNUTLS certificate credentials.
Definition gnutls.c:85
gnutls_session_t session
GNUTLS session.
Definition gnutls.c:84
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tls_starttls_close()

static int tls_starttls_close ( struct Connection * conn)
static

Close a TLS connection - Implements Connection::close() -.

Definition at line 1133 of file gnutls.c.

1134{
1135 int rc;
1136
1137 rc = tls_socket_close(conn);
1138 conn->read = raw_socket_read;
1139 conn->write = raw_socket_write;
1140 conn->close = raw_socket_close;
1141 conn->poll = raw_socket_poll;
1142
1143 return rc;
1144}
static int tls_socket_close(struct Connection *conn)
Close a TLS socket - Implements Connection::close() -.
Definition gnutls.c:1018
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:355
int raw_socket_read(struct Connection *conn, char *buf, size_t len)
Read data from a socket - Implements Connection::read() -.
Definition raw.c:295
int raw_socket_write(struct Connection *conn, const char *buf, size_t count)
Write data to a socket - Implements Connection::write() -.
Definition raw.c:325
int(* poll)(struct Connection *conn, time_t wait_secs)
Definition connection.h:105
int(* write)(struct Connection *conn, const char *buf, size_t count)
Definition connection.h:92
int(* close)(struct Connection *conn)
Definition connection.h:116
int(* read)(struct Connection *conn, char *buf, size_t count)
Definition connection.h:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ssl_socket_close_and_restore()

static int ssl_socket_close_and_restore ( struct Connection * conn)
static

Close an SSL Connection and restore Connection callbacks - Implements Connection::close() -.

Definition at line 622 of file openssl.c.

623{
624 int rc = ssl_socket_close(conn);
625 conn->read = raw_socket_read;
626 conn->write = raw_socket_write;
627 conn->close = raw_socket_close;
628 conn->poll = raw_socket_poll;
629
630 return rc;
631}
static int ssl_socket_close(struct Connection *conn)
Close an SSL connection - Implements Connection::close() -.
Definition openssl.c:1393
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ssl_socket_close()

static int ssl_socket_close ( struct Connection * conn)
static

Close an SSL connection - Implements Connection::close() -.

Definition at line 1393 of file openssl.c.

1394{
1395 struct SslSockData *data = sockdata(conn);
1396
1397 if (data)
1398 {
1399 if (data->isopen && (raw_socket_poll(conn, 0) >= 0))
1400 SSL_shutdown(data->ssl);
1401
1402 SSL_free(data->ssl);
1403 data->ssl = NULL;
1404 SSL_CTX_free(data->sctx);
1405 data->sctx = NULL;
1406 FREE(&conn->sockdata);
1407 }
1408
1409 return raw_socket_close(conn);
1410}
static struct SslSockData * sockdata(struct Connection *conn)
Get a Connection's socket data.
Definition openssl.c:1197
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ raw_socket_close()

int raw_socket_close ( struct Connection * conn)

Close a socket - Implements Connection::close() -.

Definition at line 393 of file raw.c.

394{
395 return close(conn->fd);
396}
int fd
Socket file descriptor.
Definition connection.h:53
+ Here is the caller graph for this function:

◆ mutt_sasl_conn_close()

static int mutt_sasl_conn_close ( struct Connection * conn)
static

Close SASL connection - Implements Connection::close() -.

Calls underlying close function and disposes of the sasl_conn_t object, then restores connection to pre-sasl state

Definition at line 438 of file sasl.c.

439{
440 struct SaslSockData *sasldata = conn->sockdata;
441
442 /* restore connection's underlying methods */
443 conn->sockdata = sasldata->sockdata;
444 conn->open = sasldata->open;
445 conn->read = sasldata->read;
446 conn->write = sasldata->write;
447 conn->poll = sasldata->poll;
448 conn->close = sasldata->close;
449
450 /* release sasl resources */
451 sasl_dispose(&sasldata->saslconn);
452 FREE(&sasldata);
453
454 /* call underlying close */
455 int rc = conn->close(conn);
456
457 return rc;
458}
int(* close)(struct Connection *conn)
Close a socket Connection - Implements Connection::close() -.
Definition sasl.c:99
int(* open)(struct Connection *conn)
Open a socket Connection - Implements Connection::open() -.
Definition sasl.c:79
int(* poll)(struct Connection *conn, time_t wait_secs)
Check if any data is waiting on a socket - Implements Connection::poll() -.
Definition sasl.c:94
int(* read)(struct Connection *conn, char *buf, size_t count)
Read from a socket Connection - Implements Connection::read() -.
Definition sasl.c:84
int(* write)(struct Connection *conn, const char *buf, size_t count)
Write to a socket Connection - Implements Connection::write() -.
Definition sasl.c:89
int(* open)(struct Connection *conn)
Definition connection.h:66
SASL authentication API -.
Definition sasl.c:64
void * sockdata
Underlying socket data.
Definition sasl.c:74
sasl_conn_t * saslconn
Raw SASL connection.
Definition sasl.c:65
+ Here is the caller graph for this function:

◆ tunnel_socket_close()

static int tunnel_socket_close ( struct Connection * conn)
static

Close a tunnel socket - Implements Connection::close() -.

Definition at line 213 of file tunnel.c.

214{
215 struct TunnelSockData *tunnel = conn->sockdata;
216 if (!tunnel)
217 {
218 return 0;
219 }
220
221 int status;
222
223 close(tunnel->fd_read);
224 close(tunnel->fd_write);
225 waitpid(tunnel->pid, &status, 0);
226 if (!WIFEXITED(status) || WEXITSTATUS(status))
227 {
228 mutt_error(_("Tunnel to %s returned error %d (%s)"), conn->account.host,
229 WEXITSTATUS(status), NONULL(mutt_str_sysexit(WEXITSTATUS(status))));
230 }
231 FREE(&conn->sockdata);
232
233 return 0;
234}
#define mutt_error(...)
Definition logging2.h:94
#define _(a)
Definition message.h:28
const char * mutt_str_sysexit(int err_num)
Return a string matching an error code.
Definition string.c:173
#define NONULL(x)
Definition string2.h:44
char host[128]
Server to login to.
Definition connaccount.h:54
struct ConnAccount account
Account details: username, password, etc.
Definition connection.h:49
A network tunnel (pair of sockets)
Definition tunnel.c:49
int fd_read
File descriptor to read from.
Definition tunnel.c:51
pid_t pid
Process ID of tunnel program.
Definition tunnel.c:50
int fd_write
File descriptor to write to.
Definition tunnel.c:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ zstrm_close()

static int zstrm_close ( struct Connection * conn)
static

Close a socket - Implements Connection::close() -.

Definition at line 100 of file zstrm.c.

101{
102 struct ZstrmContext *zctx = conn->sockdata;
103
104 int rc = zctx->next_conn.close(&zctx->next_conn);
105
106 double read_ratio = (zctx->read.z.total_in != 0) ?
107 (double) zctx->read.z.total_out /
108 (double) zctx->read.z.total_in :
109 0.0;
110 double write_ratio = (zctx->write.z.total_out != 0) ?
111 (double) zctx->write.z.total_in /
112 (double) zctx->write.z.total_out :
113 0.0;
114 mutt_debug(LL_DEBUG5, "read %lu->%lu (%.1fx) wrote %lu<-%lu (%.1fx)\n",
115 zctx->read.z.total_in, zctx->read.z.total_out, read_ratio,
116 zctx->write.z.total_in, zctx->write.z.total_out, write_ratio);
117
118 // Restore the Connection's original functions
119 conn->sockdata = zctx->next_conn.sockdata;
120 conn->open = zctx->next_conn.open;
121 conn->close = zctx->next_conn.close;
122 conn->read = zctx->next_conn.read;
123 conn->write = zctx->next_conn.write;
124 conn->poll = zctx->next_conn.poll;
125
126 inflateEnd(&zctx->read.z);
127 deflateEnd(&zctx->write.z);
128 FREE(&zctx->read.buf);
129 FREE(&zctx->write.buf);
130 FREE(&zctx);
131
132 return rc;
133}
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
Data compression layer.
Definition zstrm.c:58
struct ZstrmDirection read
Data being read and de-compressed.
Definition zstrm.c:59
struct ZstrmDirection write
Data being compressed and written.
Definition zstrm.c:60
struct Connection next_conn
Underlying stream.
Definition zstrm.c:61
z_stream z
zlib compression handle
Definition zstrm.c:46
char * buf
Buffer for data being (de-)compressed.
Definition zstrm.c:47
+ Here is the caller graph for this function:

Variable Documentation

◆ close

int(* SaslSockData::close) (struct Connection *conn)

Close a socket Connection - Implements Connection::close() -.

Definition at line 99 of file sasl.c.