NeoMutt  2025-12-11-1039-g550ac6
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()

int tls_socket_close ( struct Connection * conn)
static

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

Definition at line 1021 of file gnutls.c.

1022{
1023 struct TlsSockData *data = conn->sockdata;
1024 if (data)
1025 {
1026 /* shut down only the write half to avoid hanging waiting for the remote to respond.
1027 *
1028 * RFC5246 7.2.1. "Closure Alerts"
1029 *
1030 * It is not required for the initiator of the close to wait for the
1031 * responding close_notify alert before closing the read side of the
1032 * connection. */
1033 gnutls_bye(data->session, GNUTLS_SHUT_WR);
1034
1035 gnutls_certificate_free_credentials(data->xcred);
1036 gnutls_deinit(data->session);
1037 FREE(&conn->sockdata);
1038 }
1039
1040 return raw_socket_close(conn);
1041}
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
This array needs to be large enough to hold all the possible values support by NeoMutt.
Definition gnutls.c:82
gnutls_certificate_credentials_t xcred
GNUTLS certificate credentials.
Definition gnutls.c:84
gnutls_session_t session
GNUTLS session.
Definition gnutls.c:83
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tls_starttls_close()

int tls_starttls_close ( struct Connection * conn)
static

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

Definition at line 1137 of file gnutls.c.

1138{
1139 int rc;
1140
1141 rc = tls_socket_close(conn);
1142 conn->read = raw_socket_read;
1143 conn->write = raw_socket_write;
1144 conn->close = raw_socket_close;
1145 conn->poll = raw_socket_poll;
1146
1147 return rc;
1148}
static int tls_socket_close(struct Connection *conn)
Close a TLS socket - Implements Connection::close() -.
Definition gnutls.c:1021
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()

int ssl_socket_close_and_restore ( struct Connection * conn)
static

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

Definition at line 623 of file openssl.c.

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

◆ ssl_socket_close()

int ssl_socket_close ( struct Connection * conn)
static

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

Definition at line 1407 of file openssl.c.

1408{
1409 struct SslSockData *data = sockdata(conn);
1410
1411 if (data)
1412 {
1413 if (data->is_open && (raw_socket_poll(conn, 0) >= 0))
1414 SSL_shutdown(data->ssl);
1415
1416 SSL_free(data->ssl);
1417 data->ssl = NULL;
1418 SSL_CTX_free(data->sctx);
1419 data->sctx = NULL;
1420 FREE(&conn->sockdata);
1421 }
1422
1423 return raw_socket_close(conn);
1424}
static struct SslSockData * sockdata(struct Connection *conn)
Get a Connection's socket data.
Definition openssl.c:1211
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()

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 448 of file sasl.c.

449{
450 struct SaslSockData *sasldata = conn->sockdata;
451
452 /* restore connection's underlying methods */
453 conn->sockdata = sasldata->sockdata;
454 conn->open = sasldata->open;
455 conn->read = sasldata->read;
456 conn->write = sasldata->write;
457 conn->poll = sasldata->poll;
458 conn->close = sasldata->close;
459
460 /* release sasl resources */
461 sasl_dispose(&sasldata->saslconn);
462 FREE(&sasldata);
463
464 /* call underlying close */
465 int rc = conn->close(conn);
466
467 return rc;
468}
int(* close)(struct Connection *conn)
Close a socket Connection - Implements Connection::close() -.
Definition sasl.c:101
int(* open)(struct Connection *conn)
Open a socket Connection - Implements Connection::open() -.
Definition sasl.c:81
int(* poll)(struct Connection *conn, time_t wait_secs)
Check if any data is waiting on a socket - Implements Connection::poll() -.
Definition sasl.c:96
int(* read)(struct Connection *conn, char *buf, size_t count)
Read from a socket Connection - Implements Connection::read() -.
Definition sasl.c:86
int(* write)(struct Connection *conn, const char *buf, size_t count)
Write to a socket Connection - Implements Connection::write() -.
Definition sasl.c:91
int(* open)(struct Connection *conn)
Definition connection.h:66
SASL authentication API -.
Definition sasl.c:66
void * sockdata
Underlying socket data.
Definition sasl.c:76
sasl_conn_t * saslconn
Raw SASL connection.
Definition sasl.c:67
Here is the caller graph for this function:

◆ tunnel_socket_close()

int tunnel_socket_close ( struct Connection * conn)
static

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

Definition at line 214 of file tunnel.c.

215{
216 struct TunnelSockData *tunnel = conn->sockdata;
217 if (!tunnel)
218 {
219 return 0;
220 }
221
222 int status = 0;
223
224 close(tunnel->fd_read);
225 close(tunnel->fd_write);
226 waitpid(tunnel->pid, &status, 0);
227 if (!WIFEXITED(status) || WEXITSTATUS(status))
228 {
229 mutt_error(_("Tunnel to %s returned error %d (%s)"), conn->account.host,
230 WEXITSTATUS(status), NONULL(mutt_str_sysexit(WEXITSTATUS(status))));
231 }
232 FREE(&conn->sockdata);
233
234 return 0;
235}
#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:60
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()

int zstrm_close ( struct Connection * conn)
static

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

Definition at line 101 of file zstrm.c.

102{
103 struct ZstrmContext *zctx = conn->sockdata;
104
105 int rc = zctx->next_conn.close(&zctx->next_conn);
106
107 double read_ratio = (zctx->read.z.total_in != 0) ?
108 (double) zctx->read.z.total_out /
109 (double) zctx->read.z.total_in :
110 0.0;
111 double write_ratio = (zctx->write.z.total_out != 0) ?
112 (double) zctx->write.z.total_in /
113 (double) zctx->write.z.total_out :
114 0.0;
115 mutt_debug(LL_DEBUG5, "read %lu->%lu (%.1fx) wrote %lu<-%lu (%.1fx)\n",
116 zctx->read.z.total_in, zctx->read.z.total_out, read_ratio,
117 zctx->write.z.total_in, zctx->write.z.total_out, write_ratio);
118
119 // Restore the Connection's original functions
120 conn->sockdata = zctx->next_conn.sockdata;
121 conn->open = zctx->next_conn.open;
122 conn->close = zctx->next_conn.close;
123 conn->read = zctx->next_conn.read;
124 conn->write = zctx->next_conn.write;
125 conn->poll = zctx->next_conn.poll;
126
127 inflateEnd(&zctx->read.z);
128 deflateEnd(&zctx->write.z);
129 FREE(&zctx->read.buf);
130 FREE(&zctx->write.buf);
131 FREE(&zctx);
132
133 return rc;
134}
#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:59
struct ZstrmDirection read
Data being read and de-compressed.
Definition zstrm.c:60
struct ZstrmDirection write
Data being compressed and written.
Definition zstrm.c:61
struct Connection next_conn
Underlying stream.
Definition zstrm.c:62
z_stream z
zlib compression handle
Definition zstrm.c:47
char * buf
Buffer for data being (de-)compressed.
Definition zstrm.c:48
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 101 of file sasl.c.