36#include <netinet/in.h>
41#include <sys/select.h>
42#include <sys/socket.h>
55#ifdef HAVE_GETADDRINFO
73 if (sa->sa_family == AF_INET)
74 sa_size =
sizeof(
struct sockaddr_in);
75#ifdef HAVE_GETADDRINFO
76 else if (sa->sa_family == AF_INET6)
77 sa_size =
sizeof(
struct sockaddr_in6);
86 if (c_socket_timeout > 0)
87 alarm(c_socket_timeout);
94 sigaddset(&set, SIGWINCH);
95 sigprocmask(SIG_BLOCK, &set, NULL);
99 if (c_socket_timeout > 0)
101 const struct timeval tv = { c_socket_timeout, 0 };
102 if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv,
sizeof(tv)) < 0)
106 if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv,
sizeof(tv)) < 0)
112 if (connect(fd, sa, sa_size) < 0)
119 if (c_socket_timeout > 0)
122 sigprocmask(SIG_UNBLOCK, &set, NULL);
134 char *host_idna = NULL;
136#ifdef HAVE_GETADDRINFO
140 char port[6] = { 0 };
141 struct addrinfo hints;
142 struct addrinfo *res = NULL;
143 struct addrinfo *cur = NULL;
146 memset(&hints, 0,
sizeof(hints));
150 hints.ai_family = AF_UNSPEC;
152 hints.ai_family = AF_INET;
154 hints.ai_socktype = SOCK_STREAM;
156 snprintf(port,
sizeof(port),
"%d", conn->
account.
port);
171 rc = getaddrinfo(host_idna, port, &hints, &res);
187 for (cur = res; cur; cur = cur->ai_next)
189 int fd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol);
195 (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
210 struct sockaddr_in sin;
211 struct hostent *he = NULL;
213 memset(&sin, 0,
sizeof(sin));
215 sin.sin_family = AF_INET;
230 he = gethostbyname(host_idna);
247 for (
int i = 0; he->h_addr_list[i]; i++)
249 memcpy(&sin.sin_addr, he->h_addr_list[i], he->h_length);
250 int fd = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
257 fcntl(fd, F_SETFD, FD_CLOEXEC);
271 (rc > 0) ? strerror(rc) :
_(
"unknown error"));
288 rc = read(conn->
fd, buf, count);
289 }
while (rc < 0 && (errno == EINTR));
321 rc = write(conn->
fd, buf + sent, count - sent);
322 }
while (rc < 0 && (errno == EINTR));
332 }
while ((sent < count) && !
SigInt);
349 uint64_t wait_millis = wait_secs * 1000UL;
353 tv.tv_sec = wait_millis / 1000;
354 tv.tv_usec = (wait_millis % 1000) * 1000;
357 FD_SET(conn->
fd, &rfds);
360 const int rc = select(conn->
fd + 1, &rfds, NULL, NULL, &tv);
363 if ((rc > 0) || ((rc < 0) && (errno != EINTR)))
369 wait_millis += pre_t;
370 if (wait_millis <= post_t)
372 wait_millis -= post_t;
381 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
SIG_ATOMIC_VOLATILE_T SigInt
true after SIGINT is received
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)
Checks whether reads would block - 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_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.