NeoMutt  2024-11-14-34-g5aaf0d
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 1003 of file gnutls.c.

1004{
1005 struct TlsSockData *data = conn->sockdata;
1006 if (data)
1007 {
1008 /* shut down only the write half to avoid hanging waiting for the remote to respond.
1009 *
1010 * RFC5246 7.2.1. "Closure Alerts"
1011 *
1012 * It is not required for the initiator of the close to wait for the
1013 * responding close_notify alert before closing the read side of the
1014 * connection. */
1015 gnutls_bye(data->session, GNUTLS_SHUT_WR);
1016
1017 gnutls_certificate_free_credentials(data->xcred);
1018 gnutls_deinit(data->session);
1019 FREE(&conn->sockdata);
1020 }
1021
1022 return raw_socket_close(conn);
1023}
int raw_socket_close(struct Connection *conn)
Close a socket - Implements Connection::close() -.
Definition: raw.c:393
#define FREE(x)
Definition: memory.h:55
void * sockdata
Backend-specific socket data.
Definition: connection.h:55
TLS socket data -.
Definition: gnutls.c:82
gnutls_certificate_credentials_t xcred
Definition: gnutls.c:84
gnutls_session_t 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 1106 of file gnutls.c.

1107{
1108 int rc;
1109
1110 rc = tls_socket_close(conn);
1111 conn->read = raw_socket_read;
1112 conn->write = raw_socket_write;
1113 conn->close = raw_socket_close;
1114 conn->poll = raw_socket_poll;
1115
1116 return rc;
1117}
static int tls_socket_close(struct Connection *conn)
Close a TLS socket - Implements Connection::close() -.
Definition: gnutls.c:1003
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 621 of file openssl.c.

622{
623 int rc = ssl_socket_close(conn);
624 conn->read = raw_socket_read;
625 conn->write = raw_socket_write;
626 conn->close = raw_socket_close;
627 conn->poll = raw_socket_poll;
628
629 return rc;
630}
static int ssl_socket_close(struct Connection *conn)
Close an SSL connection - Implements Connection::close() -.
Definition: openssl.c:1397
+ 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 1397 of file openssl.c.

1398{
1399 struct SslSockData *data = sockdata(conn);
1400
1401 if (data)
1402 {
1403 if (data->isopen && (raw_socket_poll(conn, 0) >= 0))
1404 SSL_shutdown(data->ssl);
1405
1406 SSL_free(data->ssl);
1407 data->ssl = NULL;
1408 SSL_CTX_free(data->sctx);
1409 data->sctx = NULL;
1410 FREE(&conn->sockdata);
1411 }
1412
1413 return raw_socket_close(conn);
1414}
static struct SslSockData * sockdata(struct Connection *conn)
Get a Connection's socket data.
Definition: openssl.c:1194
+ 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 443 of file sasl.c.

444{
445 struct SaslSockData *sasldata = conn->sockdata;
446
447 /* restore connection's underlying methods */
448 conn->sockdata = sasldata->sockdata;
449 conn->open = sasldata->open;
450 conn->read = sasldata->read;
451 conn->write = sasldata->write;
452 conn->poll = sasldata->poll;
453 conn->close = sasldata->close;
454
455 /* release sasl resources */
456 sasl_dispose(&sasldata->saslconn);
457 FREE(&sasldata);
458
459 /* call underlying close */
460 int rc = conn->close(conn);
461
462 return rc;
463}
int(* close)(struct Connection *conn)
Close a socket Connection - Implements Connection::close() -.
Definition: sasl.c:100
int(* open)(struct Connection *conn)
Open a socket Connection - Implements Connection::open() -.
Definition: sasl.c:80
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
int(* read)(struct Connection *conn, char *buf, size_t count)
Read from a socket Connection - Implements Connection::read() -.
Definition: sasl.c:85
int(* write)(struct Connection *conn, const char *buf, size_t count)
Write to a socket Connection - Implements Connection::write() -.
Definition: sasl.c:90
int(* open)(struct Connection *conn)
Definition: connection.h:66
SASL authentication API -.
Definition: sasl.c:65
void * sockdata
Underlying socket data.
Definition: sasl.c:75
sasl_conn_t * saslconn
Definition: sasl.c:66
+ 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:92
#define _(a)
Definition: message.h:28
const char * mutt_str_sysexit(int err_num)
Return a string matching an error code.
Definition: string.c:169
#define NONULL(x)
Definition: string2.h:37
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:50
int fd_read
File descriptor to read from.
Definition: tunnel.c:52
pid_t pid
Process ID of tunnel program.
Definition: tunnel.c:51
int fd_write
File descriptor to write to.
Definition: tunnel.c:53
+ 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 mutt_debug(LL_DEBUG5, "read %lu->%lu (%.1fx) wrote %lu<-%lu (%.1fx)\n",
107 zctx->read.z.total_in, zctx->read.z.total_out,
108 (double) zctx->read.z.total_out / (double) zctx->read.z.total_in,
109 zctx->write.z.total_in, zctx->write.z.total_out,
110 (double) zctx->write.z.total_in / (double) zctx->write.z.total_out);
111
112 // Restore the Connection's original functions
113 conn->sockdata = zctx->next_conn.sockdata;
114 conn->open = zctx->next_conn.open;
115 conn->close = zctx->next_conn.close;
116 conn->read = zctx->next_conn.read;
117 conn->write = zctx->next_conn.write;
118 conn->poll = zctx->next_conn.poll;
119
120 inflateEnd(&zctx->read.z);
121 deflateEnd(&zctx->write.z);
122 FREE(&zctx->read.buf);
123 FREE(&zctx->write.buf);
124 FREE(&zctx);
125
126 return rc;
127}
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
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 100 of file sasl.c.