NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
raw.c File Reference

Low-level socket handling. More...

#include "config.h"
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "mutt_globals.h"
#include "options.h"
#include <stdbool.h>
+ Include dependency graph for raw.c:

Go to the source code of this file.

Functions

static int socket_connect (int fd, struct sockaddr *sa)
 set up to connect to a socket fd More...
 
int raw_socket_open (struct Connection *conn)
 Open a socket - Implements Connection::open() -. More...
 
int raw_socket_read (struct Connection *conn, char *buf, size_t count)
 Read data from a socket - Implements Connection::read() -. More...
 
int raw_socket_write (struct Connection *conn, const char *buf, size_t count)
 Write data to a socket - Implements Connection::write() -. More...
 
int raw_socket_poll (struct Connection *conn, time_t wait_secs)
 Checks whether reads would block - Implements Connection::poll() -. More...
 
int raw_socket_close (struct Connection *conn)
 Close a socket - Implements Connection::close() -. More...
 

Detailed Description

Low-level socket handling.

Authors
  • Michael R. Elkins
  • Brendan Cully
  • Tommi Komulainen
  • Damien Riegel

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file raw.c.

Function Documentation

◆ socket_connect()

static int socket_connect ( int  fd,
struct sockaddr *  sa 
)
static

set up to connect to a socket fd

Parameters
fdFile descriptor to connect with
saAddress info
Return values
0Success
>0An errno, e.g. EPERM
-1Error

Definition at line 69 of file raw.c.

70 {
71  int sa_size;
72  int save_errno;
73  sigset_t set;
74 
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);
80 #endif
81  else
82  {
83  mutt_debug(LL_DEBUG1, "Unknown address family!\n");
84  return -1;
85  }
86 
87  const short c_connect_timeout =
88  cs_subset_number(NeoMutt->sub, "connect_timeout");
89  if (c_connect_timeout > 0)
90  alarm(c_connect_timeout);
91 
93 
94  /* FreeBSD's connect() does not respect SA_RESTART, meaning
95  * a SIGWINCH will cause the connect to fail. */
96  sigemptyset(&set);
97  sigaddset(&set, SIGWINCH);
98  sigprocmask(SIG_BLOCK, &set, NULL);
99 
100  save_errno = 0;
101 
102  if (connect(fd, sa, sa_size) < 0)
103  {
104  save_errno = errno;
105  mutt_debug(LL_DEBUG2, "Connection failed. errno: %d\n", errno);
106  SigInt = false; /* reset in case we caught SIGINTR while in connect() */
107  }
108 
109  if (c_connect_timeout > 0)
110  alarm(0);
112  sigprocmask(SIG_UNBLOCK, &set, NULL);
113 
114  return save_errno;
115 }
WHERE SIG_ATOMIC_VOLATILE_T SigInt
true after SIGINT is received
Definition: mutt_globals.h:67
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
Container for Accounts, Notifications.
Definition: neomutt.h:36
void mutt_sig_allow_interrupt(bool allow)
Allow/disallow Ctrl-C (SIGINT)
Definition: signal.c:238
Log at debug level 2.
Definition: logging.h:41
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Log at debug level 1.
Definition: logging.h:40
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function: