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

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

1104{
1105 int rc;
1106
1107 rc = tls_socket_close(conn);
1108 conn->read = raw_socket_read;
1109 conn->write = raw_socket_write;
1110 conn->close = raw_socket_close;
1111 conn->poll = raw_socket_poll;
1112
1113 return rc;
1114}
static int tls_socket_close(struct Connection *conn)
Close a TLS socket - Implements Connection::close() -.
Definition: gnutls.c:1000
int raw_socket_poll(struct Connection *conn, time_t wait_secs)
Checks whether reads would block - Implements Connection::poll() -.
Definition: raw.c:341
int raw_socket_read(struct Connection *conn, char *buf, size_t len)
Read data from a socket - Implements Connection::read() -.
Definition: raw.c:281
int raw_socket_write(struct Connection *conn, const char *buf, size_t count)
Write data to a socket - Implements Connection::write() -.
Definition: raw.c:311
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 379 of file raw.c.

380{
381 return close(conn->fd);
382}
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 442 of file sasl.c.

443{
444 struct SaslSockData *sasldata = conn->sockdata;
445
446 /* restore connection's underlying methods */
447 conn->sockdata = sasldata->sockdata;
448 conn->open = sasldata->open;
449 conn->read = sasldata->read;
450 conn->write = sasldata->write;
451 conn->poll = sasldata->poll;
452 conn->close = sasldata->close;
453
454 /* release sasl resources */
455 sasl_dispose(&sasldata->saslconn);
456 FREE(&sasldata);
457
458 /* call underlying close */
459 int rc = conn->close(conn);
460
461 return rc;
462}
int(* close)(struct Connection *conn)
Close a socket Connection - Implements Connection::close() -.
Definition: sasl.c:99
int(* open)(struct Connection *conn)
Open a socket Connection - Implements Connection::open() -.
Definition: sasl.c:79
int(* poll)(struct Connection *conn, time_t wait_secs)
Check whether a socket read would block - Implements Connection::poll() -.
Definition: sasl.c:94
int(* read)(struct Connection *conn, char *buf, size_t count)
Read from a socket Connection - Implements Connection::read() -.
Definition: sasl.c:84
int(* write)(struct Connection *conn, const char *buf, size_t count)
Write to a socket Connection - Implements Connection::write() -.
Definition: sasl.c:89
int(* open)(struct Connection *conn)
Definition: connection.h:67
SASL authentication API -.
Definition: sasl.c:64
void * sockdata
Underlying socket data.
Definition: sasl.c:74
sasl_conn_t * saslconn
Definition: sasl.c:65
+ 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:167
#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: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 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: logging2.h:89
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
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 99 of file sasl.c.