NeoMutt  2022-04-29-249-gaae397
Teaching an old dog new tricks
DOXYGEN

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() -. More...
 
static int tls_starttls_close (struct Connection *conn)
 Close a TLS connection - Implements Connection::close() -. More...
 
static int ssl_socket_close_and_restore (struct Connection *conn)
 Close an SSL Connection and restore Connection callbacks - Implements Connection::close() -. More...
 
static int ssl_socket_close (struct Connection *conn)
 Close an SSL connection - Implements Connection::close() -. More...
 
int raw_socket_close (struct Connection *conn)
 Close a socket - Implements Connection::close() -. More...
 
static int mutt_sasl_conn_close (struct Connection *conn)
 Close SASL connection - Implements Connection::close() -. More...
 
static int tunnel_socket_close (struct Connection *conn)
 Close a tunnel socket - Implements Connection::close() -. More...
 
static int zstrm_close (struct Connection *conn)
 Close a socket - Implements Connection::close() -. More...
 

Variables

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

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 1001 of file gnutls.c.

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

1105{
1106 int rc;
1107
1108 rc = tls_socket_close(conn);
1109 conn->read = raw_socket_read;
1110 conn->write = raw_socket_write;
1111 conn->close = raw_socket_close;
1112 conn->poll = raw_socket_poll;
1113
1114 return rc;
1115}
static int tls_socket_close(struct Connection *conn)
Close a TLS socket - Implements Connection::close() -.
Definition: gnutls.c:1001
int raw_socket_poll(struct Connection *conn, time_t wait_secs)
Checks whether reads would block - Implements Connection::poll() -.
Definition: raw.c:324
int raw_socket_read(struct Connection *conn, char *buf, size_t len)
Read data from a socket - Implements Connection::read() -.
Definition: raw.c:264
int raw_socket_write(struct Connection *conn, const char *buf, size_t count)
Write data to a socket - Implements Connection::write() -.
Definition: raw.c:294
int(* poll)(struct Connection *conn, time_t wait_secs)
Definition: connection.h:106
int(* write)(struct Connection *conn, const char *buf, size_t count)
Definition: connection.h:93
int(* close)(struct Connection *conn)
Definition: connection.h:117
int(* read)(struct Connection *conn, char *buf, size_t count)
Definition: connection.h:80
+ 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:1369
+ 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 1369 of file openssl.c.

1370{
1371 struct SslSockData *data = sockdata(conn);
1372
1373 if (data)
1374 {
1375 if (data->isopen && (raw_socket_poll(conn, 0) >= 0))
1376 SSL_shutdown(data->ssl);
1377
1378 SSL_free(data->ssl);
1379 data->ssl = NULL;
1380 SSL_CTX_free(data->sctx);
1381 data->sctx = NULL;
1382 FREE(&conn->sockdata);
1383 }
1384
1385 return raw_socket_close(conn);
1386}
static struct SslSockData * sockdata(struct Connection *conn)
Get a Connection's socket data.
Definition: openssl.c:1183
+ 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 362 of file raw.c.

363{
364 return close(conn->fd);
365}
int fd
Socket file descriptor.
Definition: connection.h:54
+ 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:97
int(* open)(struct Connection *conn)
Open a socket Connection - Implements Connection::open() -.
Definition: sasl.c:77
int(* poll)(struct Connection *conn, time_t wait_secs)
Check whether a socket read would block - Implements Connection::poll() -.
Definition: sasl.c:92
int(* read)(struct Connection *conn, char *buf, size_t count)
Read from a socket Connection - Implements Connection::read() -.
Definition: sasl.c:82
int(* write)(struct Connection *conn, const char *buf, size_t count)
Write to a socket Connection - Implements Connection::write() -.
Definition: sasl.c:87
int(* open)(struct Connection *conn)
Definition: connection.h:67
SASL authentication API -.
Definition: sasl.c:62
void * sockdata
Underlying socket data.
Definition: sasl.c:72
sasl_conn_t * saslconn
Definition: sasl.c:63
+ 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 204 of file tunnel.c.

205{
206 struct TunnelSockData *tunnel = conn->sockdata;
207 if (!tunnel)
208 {
209 return 0;
210 }
211
212 int status;
213
214 close(tunnel->fd_read);
215 close(tunnel->fd_write);
216 waitpid(tunnel->pid, &status, 0);
217 if (!WIFEXITED(status) || WEXITSTATUS(status))
218 {
219 mutt_error(_("Tunnel to %s returned error %d (%s)"), conn->account.host,
220 WEXITSTATUS(status), NONULL(mutt_str_sysexit(WEXITSTATUS(status))));
221 }
222 FREE(&conn->sockdata);
223
224 return 0;
225}
#define mutt_error(...)
Definition: logging.h:87
#define _(a)
Definition: message.h:28
const char * mutt_str_sysexit(int err_num)
Return a string matching an error code.
Definition: string.c:166
#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:50
A network tunnel (pair of sockets)
Definition: tunnel.c:48
int fd_read
File descriptor to read from.
Definition: tunnel.c:50
pid_t pid
Process ID of tunnel program.
Definition: tunnel.c:49
int fd_write
File descriptor to write to.
Definition: tunnel.c:51
+ 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 97 of file zstrm.c.

98{
99 struct ZstrmContext *zctx = conn->sockdata;
100
101 int rc = zctx->next_conn.close(&zctx->next_conn);
102
103 mutt_debug(LL_DEBUG5, "read %lu->%lu (%.1fx) wrote %lu<-%lu (%.1fx)\n",
104 zctx->read.z.total_in, zctx->read.z.total_out,
105 (float) zctx->read.z.total_out / (float) zctx->read.z.total_in,
106 zctx->write.z.total_in, zctx->write.z.total_out,
107 (float) zctx->write.z.total_in / (float) zctx->write.z.total_out);
108
109 // Restore the Connection's original functions
110 conn->sockdata = zctx->next_conn.sockdata;
111 conn->open = zctx->next_conn.open;
112 conn->close = zctx->next_conn.close;
113 conn->read = zctx->next_conn.read;
114 conn->write = zctx->next_conn.write;
115 conn->poll = zctx->next_conn.poll;
116
117 inflateEnd(&zctx->read.z);
118 deflateEnd(&zctx->write.z);
119 FREE(&zctx->read.buf);
120 FREE(&zctx->write.buf);
121 FREE(&zctx);
122
123 return rc;
124}
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
@ LL_DEBUG5
Log at debug level 5.
Definition: logging.h:44
Data compression layer.
Definition: zstrm.c:55
struct ZstrmDirection read
Data being read and de-compressed.
Definition: zstrm.c:56
struct ZstrmDirection write
Data being compressed and written.
Definition: zstrm.c:57
struct Connection next_conn
Underlying stream.
Definition: zstrm.c:58
z_stream z
zlib compression handle
Definition: zstrm.c:43
char * buf
Buffer for data being (de-)compressed.
Definition: zstrm.c:44
+ 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 97 of file sasl.c.