36#include <netinet/in.h>
41#include <sys/select.h>
42#include <sys/socket.h>
54#ifdef HAVE_GETADDRINFO
72 if (sa->sa_family == AF_INET)
73 sa_size =
sizeof(
struct sockaddr_in);
74#ifdef HAVE_GETADDRINFO
75 else if (sa->sa_family == AF_INET6)
76 sa_size =
sizeof(
struct sockaddr_in6);
85 if (c_socket_timeout > 0)
86 alarm(c_socket_timeout);
93 sigaddset(&set, SIGWINCH);
94 sigprocmask(SIG_BLOCK, &set, NULL);
98 if (c_socket_timeout > 0)
100 const struct timeval tv = { c_socket_timeout, 0 };
101 if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv,
sizeof(tv)) < 0)
105 if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv,
sizeof(tv)) < 0)
111 if (connect(fd, sa, sa_size) < 0)
118 if (c_socket_timeout > 0)
121 sigprocmask(SIG_UNBLOCK, &set, NULL);
133 char *host_idna = NULL;
135#ifdef HAVE_GETADDRINFO
139 char port[6] = { 0 };
140 struct addrinfo hints;
141 struct addrinfo *res = NULL;
142 struct addrinfo *cur = NULL;
145 memset(&hints, 0,
sizeof(hints));
149 hints.ai_family = AF_UNSPEC;
151 hints.ai_family = AF_INET;
153 hints.ai_socktype = SOCK_STREAM;
155 snprintf(port,
sizeof(port),
"%d", conn->
account.
port);
170 rc = getaddrinfo(host_idna, port, &hints, &res);
186 for (cur = res; cur; cur = cur->ai_next)
188 int fd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol);
194 (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
207 struct sockaddr_in sin;
208 struct hostent *he = NULL;
210 memset(&sin, 0,
sizeof(sin));
212 sin.sin_family = AF_INET;
227 he = gethostbyname(host_idna);
244 for (
int i = 0; he->h_addr_list[i]; i++)
246 memcpy(&sin.sin_addr, he->h_addr_list[i], he->h_length);
247 int fd = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
254 fcntl(fd, F_SETFD, FD_CLOEXEC);
266 (rc > 0) ? strerror(rc) :
_(
"unknown error"));
283 rc = read(conn->
fd, buf, count);
284 }
while (rc < 0 && (errno == EINTR));
316 rc = write(conn->
fd, buf + sent, count - sent);
317 }
while (rc < 0 && (errno == EINTR));
327 }
while ((sent < count) && !
SigInt);
344 uint64_t wait_millis = wait_secs * 1000UL;
348 tv.tv_sec = wait_millis / 1000;
349 tv.tv_usec = (wait_millis % 1000) * 1000;
352 FD_SET(conn->
fd, &rfds);
355 const int rc = select(conn->
fd + 1, &rfds, NULL, NULL, &tv);
358 if ((rc > 0) || ((rc < 0) && (errno != EINTR)))
364 wait_millis += pre_t;
365 if (wait_millis <= post_t)
367 wait_millis -= post_t;
376 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.
Convenience wrapper for the core headers.
void mutt_query_exit(void)
Ask the user if they want to leave NeoMutt.
uint64_t mutt_date_now_ms(void)
Return the number of milliseconds since the Unix epoch.
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.
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.