NeoMutt  2025-12-11-980-ge38c27
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 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:392
#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()

static int tls_starttls_close ( struct Connection * conn)
static

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

Definition at line 1136 of file gnutls.c.

1137{
1138 int rc;
1139
1140 rc = tls_socket_close(conn);
1141 conn->read = raw_socket_read;
1142 conn->write = raw_socket_write;
1143 conn->close = raw_socket_close;
1144 conn->poll = raw_socket_poll;
1145
1146 return rc;
1147}
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:354
int raw_socket_read(struct Connection *conn, char *buf, size_t len)
Read data from a socket - Implements Connection::read() -.
Definition raw.c:294
int raw_socket_write(struct Connection *conn, const char *buf, size_t count)
Write data to a socket - Implements Connection::write() -.
Definition raw.c:324
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 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()

static 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->isopen && (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 392 of file raw.c.

393{
394 return close(conn->fd);
395}
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 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()

static 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()

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