NeoMutt  2024-02-01-25-ga71e95
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 1002 of file gnutls.c.

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

1106{
1107 int rc;
1108
1109 rc = tls_socket_close(conn);
1110 conn->read = raw_socket_read;
1111 conn->write = raw_socket_write;
1112 conn->close = raw_socket_close;
1113 conn->poll = raw_socket_poll;
1114
1115 return rc;
1116}
static int tls_socket_close(struct Connection *conn)
Close a TLS socket - Implements Connection::close() -.
Definition: gnutls.c:1002
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:336
int raw_socket_read(struct Connection *conn, char *buf, size_t len)
Read data from a socket - Implements Connection::read() -.
Definition: raw.c:276
int raw_socket_write(struct Connection *conn, const char *buf, size_t count)
Write data to a socket - Implements Connection::write() -.
Definition: raw.c:306
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 625 of file openssl.c.

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

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

375{
376 return close(conn->fd);
377}
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 212 of file tunnel.c.

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