35#include <netinet/in.h>
40#include <sys/select.h>
41#include <sys/socket.h>
55#ifdef HAVE_GETADDRINFO
72 struct sigaction oldalrm = { 0 };
73 struct sigaction act = { 0 };
75 if (sa->sa_family == AF_INET)
76 sa_size =
sizeof(
struct sockaddr_in);
77#ifdef HAVE_GETADDRINFO
78 else if (sa->sa_family == AF_INET6)
79 sa_size =
sizeof(
struct sockaddr_in6);
83 mutt_debug(LL_DEBUG1,
"Unknown address family!\n");
90 if (c_socket_timeout > 0)
92 sigemptyset(&act.sa_mask);
95 act.sa_flags = SA_INTERRUPT;
99 sigaction(SIGALRM, &act, &oldalrm);
100 alarm(c_socket_timeout);
108 sigaddset(&set, SIGWINCH);
109 sigprocmask(SIG_BLOCK, &set, NULL);
113 if (c_socket_timeout > 0)
115 const struct timeval tv = { c_socket_timeout, 0 };
116 if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv,
sizeof(tv)) < 0)
120 if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv,
sizeof(tv)) < 0)
126 if (connect(fd, sa, sa_size) < 0)
133 if (c_socket_timeout > 0)
136 sigaction(SIGALRM, &oldalrm, NULL);
139 sigprocmask(SIG_UNBLOCK, &set, NULL);
151 char *host_idna = NULL;
153#ifdef HAVE_GETADDRINFO
157 char port[6] = { 0 };
158 struct addrinfo hints = { 0 };
159 struct addrinfo *res = NULL;
160 struct addrinfo *cur = NULL;
165 hints.ai_family = AF_UNSPEC;
167 hints.ai_family = AF_INET;
169 hints.ai_socktype = SOCK_STREAM;
171 snprintf(port,
sizeof(port),
"%d", conn->
account.
port);
186 rc = getaddrinfo(host_idna, port, &hints, &res);
202 for (cur = res; cur; cur = cur->ai_next)
204 int fd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol);
210 (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
225 struct hostent *he = NULL;
226 struct sockaddr_in sin = { 0 };
228 sin.sin_family = AF_INET;
243 he = gethostbyname(host_idna);
260 for (
int i = 0; he->h_addr_list[i]; i++)
262 memcpy(&sin.sin_addr, he->h_addr_list[i], he->h_length);
263 int fd = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
270 fcntl(fd, F_SETFD, FD_CLOEXEC);
284 (rc > 0) ? strerror(rc) :
_(
"unknown error"));
301 rc = read(conn->
fd, buf, count);
302 }
while (rc < 0 && (errno == EINTR));
334 rc = write(conn->
fd, buf + sent, count - sent);
335 }
while (rc < 0 && (errno == EINTR));
345 }
while ((sent < count) && !
SigInt);
360 struct timeval tv = { 0 };
362 uint64_t wait_millis = wait_secs * 1000UL;
366 tv.tv_sec = wait_millis / 1000;
367 tv.tv_usec = (wait_millis % 1000) * 1000;
370 FD_SET(conn->
fd, &rfds);
373 const int rc = select(conn->
fd + 1, &rfds, NULL, NULL, &tv);
376 if ((rc > 0) || ((rc < 0) && (errno != EINTR)))
382 wait_millis += pre_t;
383 if (wait_millis <= post_t)
385 wait_millis -= post_t;
394 return close(conn->
fd);
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Convenience wrapper for the config headers.
Shared functions that are private to Connections.
An open network connection (socket)
Convenience wrapper for the core headers.
void mutt_query_exit(void)
Ask the user if they want to leave NeoMutt.
bool OptGui
(pseudo) when the gui (and curses) are started
int raw_socket_close(struct Connection *conn)
Close a socket - Implements Connection::close() -.
int raw_socket_open(struct Connection *conn)
Open a socket - Implements Connection::open() -.
int raw_socket_poll(struct Connection *conn, time_t wait_secs)
Check if any data is waiting on a socket - Implements Connection::poll() -.
int raw_socket_read(struct Connection *conn, char *buf, size_t count)
Read data from a socket - Implements Connection::read() -.
int raw_socket_write(struct Connection *conn, const char *buf, size_t count)
Write data to a socket - Implements Connection::write() -.
#define mutt_message(...)
#define mutt_debug(LEVEL,...)
Convenience wrapper for the gui headers.
int mutt_idna_to_ascii_lz(const char *input, char **output, uint8_t flags)
Convert a domain to Punycode.
@ LL_DEBUG2
Log at debug level 2.
#define FREE(x)
Free memory and set the pointer to NULL.
uint64_t mutt_date_now_ms(void)
Return the number of milliseconds since the Unix epoch.
Convenience wrapper for the library headers.
static int socket_connect(int fd, struct sockaddr *sa)
Set up to connect to a socket fd.
void mutt_sig_empty_handler(int sig)
Dummy signal handler.
volatile sig_atomic_t SigInt
true after SIGINT is received
void mutt_sig_allow_interrupt(bool allow)
Allow/disallow Ctrl-C (SIGINT)
char host[128]
Server to login to.
unsigned short port
Port to connect to.
struct ConnAccount account
Account details: username, password, etc.
int fd
Socket file descriptor.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.