35#include <netinet/in.h>
40#include <sys/select.h>
41#include <sys/socket.h>
54#ifdef HAVE_GETADDRINFO
71 struct sigaction oldalrm = { 0 };
72 struct sigaction act = { 0 };
74 if (sa->sa_family == AF_INET)
75 sa_size =
sizeof(
struct sockaddr_in);
76#ifdef HAVE_GETADDRINFO
77 else if (sa->sa_family == AF_INET6)
78 sa_size =
sizeof(
struct sockaddr_in6);
89 if (c_socket_timeout > 0)
91 sigemptyset(&act.sa_mask);
94 act.sa_flags = SA_INTERRUPT;
98 sigaction(SIGALRM, &act, &oldalrm);
99 alarm(c_socket_timeout);
107 sigaddset(&set, SIGWINCH);
108 sigprocmask(SIG_BLOCK, &set, NULL);
112 if (c_socket_timeout > 0)
114 const struct timeval tv = { c_socket_timeout, 0 };
115 if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv,
sizeof(tv)) < 0)
119 if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv,
sizeof(tv)) < 0)
125 if (connect(fd, sa, sa_size) < 0)
132 if (c_socket_timeout > 0)
135 sigaction(SIGALRM, &oldalrm, NULL);
138 sigprocmask(SIG_UNBLOCK, &set, NULL);
150 char *host_idna = NULL;
152#ifdef HAVE_GETADDRINFO
156 char port[6] = { 0 };
157 struct addrinfo hints = { 0 };
158 struct addrinfo *res = NULL;
159 struct addrinfo *cur = NULL;
164 hints.ai_family = AF_UNSPEC;
166 hints.ai_family = AF_INET;
168 hints.ai_socktype = SOCK_STREAM;
170 snprintf(port,
sizeof(port),
"%d", conn->
account.
port);
185 rc = getaddrinfo(host_idna, port, &hints, &res);
201 for (cur = res; cur; cur = cur->ai_next)
203 int fd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol);
209 (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
224 struct hostent *he = NULL;
225 struct sockaddr_in sin = { 0 };
227 sin.sin_family = AF_INET;
242 he = gethostbyname(host_idna);
259 for (
int i = 0; he->h_addr_list[i]; i++)
261 memcpy(&sin.sin_addr, he->h_addr_list[i], he->h_length);
262 int fd = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
269 fcntl(fd, F_SETFD, FD_CLOEXEC);
283 (rc > 0) ? strerror(rc) :
_(
"unknown error"));
300 rc = read(conn->
fd, buf, count);
301 }
while (rc < 0 && (errno == EINTR));
333 rc = write(conn->
fd, buf + sent, count - sent);
334 }
while (rc < 0 && (errno == EINTR));
344 }
while ((sent < count) && !
SigInt);
359 struct timeval tv = { 0 };
361 uint64_t wait_millis = wait_secs * 1000UL;
365 tv.tv_sec = wait_millis / 1000;
366 tv.tv_usec = (wait_millis % 1000) * 1000;
369 FD_SET(conn->
fd, &rfds);
372 const int rc = select(conn->
fd + 1, &rfds, NULL, NULL, &tv);
375 if ((rc > 0) || ((rc < 0) && (errno != EINTR)))
381 wait_millis += pre_t;
382 if (wait_millis <= post_t)
384 wait_millis -= post_t;
393 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.
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 OptNoCurses
(pseudo) when sending in batch mode
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.
@ LL_DEBUG1
Log at debug level 1.
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.