Skip to content

Commit

Permalink
main: use re_sock_t
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Apr 11, 2022
1 parent 7b44bee commit f9479bf
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 42 deletions.
2 changes: 1 addition & 1 deletion include/re.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ extern "C" {
#include "re_ice.h"
#include "re_jbuf.h"
#include "re_lock.h"
#include "re_net.h"
#include "re_main.h"
#include "re_md5.h"
#include "re_mem.h"
#include "re_mod.h"
#include "re_mqueue.h"
#include "re_net.h"
#include "re_odict.h"
#include "re_json.h"
#include "re_rtmp.h"
Expand Down
4 changes: 2 additions & 2 deletions include/re_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ typedef void (fd_h)(int flags, void *arg);
typedef void (re_signal_h)(int sig);


int fd_listen(int fd, int flags, fd_h *fh, void *arg);
void fd_close(int fd);
int fd_listen(re_sock_t fd, int flags, fd_h *fh, void *arg);
void fd_close(re_sock_t fd);
int fd_setsize(int maxfds);
void fd_debug(void);

Expand Down
25 changes: 12 additions & 13 deletions include/re_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
#include <arpa/inet.h>
#endif

/* Socket helpers */
#ifdef WIN32
#define ERRNO_SOCK WSAGetLastError()
#define BAD_SOCK INVALID_SOCKET
typedef size_t re_sock_t;
#else
#define ERRNO_SOCK errno
#define BAD_SOCK -1
typedef int re_sock_t;
#endif

/** Length of IPv4 address string */
#ifndef INET_ADDRSTRLEN
Expand Down Expand Up @@ -50,8 +60,8 @@ void net_sock_close(void);


/* Net socket options */
int net_sockopt_blocking_set(int fd, bool blocking);
int net_sockopt_reuse_set(int fd, bool reuse);
int net_sockopt_blocking_set(re_sock_t fd, bool blocking);
int net_sockopt_reuse_set(re_sock_t fd, bool reuse);


/* Net interface (if.c) */
Expand Down Expand Up @@ -106,14 +116,3 @@ int net_rt_debug(struct re_printf *pf, void *unused);
const char *net_proto2name(int proto);
const char *net_af2name(int af);


/* Socket helpers */
#ifdef WIN32
#define ERRNO_SOCK WSAGetLastError()
#define BAD_SOCK INVALID_SOCKET
typedef size_t re_sock_t;
#else
#define ERRNO_SOCK errno
#define BAD_SOCK -1
typedef int re_sock_t;
#endif
32 changes: 14 additions & 18 deletions src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#endif
#include <re_types.h>
#include <re_fmt.h>
#include <re_net.h>
#include <re_mem.h>
#include <re_mbuf.h>
#include <re_list.h>
Expand Down Expand Up @@ -66,7 +67,7 @@ enum {

/** File descriptor handler struct */
struct fhs {
int fd; /**< File Descriptor */
re_sock_t fd; /**< File Descriptor */
int flags; /**< Polling flags (Read, Write, etc.) */
fd_h* fh; /**< Event handler */
void* arg; /**< Handler argument */
Expand Down Expand Up @@ -214,7 +215,7 @@ static struct re *re_get(void)
*
* @return fhs index if success, otherwise -1
*/
static int lookup_fd_index(struct re* re, int fd) {
static int lookup_fd_index(struct re* re, re_sock_t fd) {
int i;

for (i = 0; i < re->nfds; i++) {
Expand Down Expand Up @@ -266,7 +267,7 @@ static void fd_handler(struct re *re, int i, int flags)


#ifdef HAVE_POLL
static int set_poll_fds(struct re *re, int fd, int flags)
static int set_poll_fds(struct re *re, re_sock_t fd, int flags)
{
if (!re->fds)
return 0;
Expand All @@ -290,7 +291,7 @@ static int set_poll_fds(struct re *re, int fd, int flags)


#ifdef HAVE_EPOLL
static int set_epoll_fds(struct re *re, int fd, int flags)
static int set_epoll_fds(struct re *re, re_sock_t fd, int flags)
{
struct epoll_event event;
int err = 0;
Expand Down Expand Up @@ -349,7 +350,7 @@ static int set_epoll_fds(struct re *re, int fd, int flags)


#ifdef HAVE_KQUEUE
static int set_kqueue_fds(struct re *re, int fd, int flags)
static int set_kqueue_fds(struct re *re, re_sock_t fd, int flags)
{
struct kevent kev[2];
int r, n = 0;
Expand Down Expand Up @@ -579,15 +580,15 @@ static int poll_setup(struct re *re)
*
* @return 0 if success, otherwise errorcode
*/
int fd_listen(int fd, int flags, fd_h *fh, void *arg)
int fd_listen(re_sock_t fd, int flags, fd_h *fh, void *arg)
{
struct re *re = re_get();
int err = 0;
int i = fd;
re_sock_t i = fd;

DEBUG_INFO("fd_listen: fd=%d flags=0x%02x\n", fd, flags);

if (fd < 0) {
if (fd == BAD_SOCK) {
DEBUG_WARNING("fd_listen: corrupt fd %d\n", fd);
return EBADF;
}
Expand Down Expand Up @@ -669,7 +670,7 @@ int fd_listen(int fd, int flags, fd_h *fh, void *arg)
*
* @param fd File descriptor
*/
void fd_close(int fd)
void fd_close(re_sock_t fd)
{
(void)fd_listen(fd, 0, NULL, NULL);
}
Expand Down Expand Up @@ -712,7 +713,7 @@ static int fd_poll(struct re *re)
FD_ZERO(&efds);

for (i=0; i<re->nfds; i++) {
int fd = re->fhs[i].fd;
re_sock_t fd = re->fhs[i].fd;
if (!re->fhs[i].fh)
continue;

Expand Down Expand Up @@ -766,17 +767,12 @@ static int fd_poll(struct re *re)
return EINVAL;
}

#ifdef WIN32
if (n == SOCKET_ERROR) {
return WSAGetLastError();
}
#else
if (n < 0)
return errno;
#endif
return ERRNO_SOCK;

/* Check for events */
for (i=0; (n > 0) && (i < re->nfds); i++) {
int fd, flags = 0;
re_sock_t fd, flags = 0;

switch (re->method) {

Expand Down
1 change: 1 addition & 0 deletions src/main/method.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <re_types.h>
#include <re_fmt.h>
#include <re_mbuf.h>
#include <re_net.h>
#include <re_main.h>
#include "main.h"

Expand Down
4 changes: 2 additions & 2 deletions src/mqueue/mqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include <re_types.h>
#include <re_fmt.h>
#include <re_mem.h>
#include <re_main.h>
#include <re_net.h>
#include <re_main.h>
#include <re_mqueue.h>
#include "mqueue.h"

Expand All @@ -33,7 +33,7 @@
* incoming messages from other threads. The sender thread can be any thread.
*/
struct mqueue {
int pfd[2];
re_sock_t pfd[2];
mqueue_h *h;
void *arg;
};
Expand Down
4 changes: 2 additions & 2 deletions src/net/sockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*
* @return 0 if success, otherwise errorcode
*/
int net_sockopt_blocking_set(int fd, bool blocking)
int net_sockopt_blocking_set(re_sock_t fd, bool blocking)
{
#ifdef WIN32
unsigned long noblock = !blocking;
Expand Down Expand Up @@ -81,7 +81,7 @@ int net_sockopt_blocking_set(int fd, bool blocking)
*
* @return 0 if success, otherwise errorcode
*/
int net_sockopt_reuse_set(int fd, bool reuse)
int net_sockopt_reuse_set(re_sock_t fd, bool reuse)
{
int r = reuse;

Expand Down
2 changes: 1 addition & 1 deletion src/tcp/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#include <re_mem.h>
#include <re_mbuf.h>
#include <re_list.h>
#include <re_net.h>
#include <re_main.h>
#include <re_sa.h>
#include <re_net.h>
#include <re_tcp.h>


Expand Down
2 changes: 1 addition & 1 deletion src/tls/openssl/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#include <re_fmt.h>
#include <re_mem.h>
#include <re_mbuf.h>
#include <re_net.h>
#include <re_main.h>
#include <re_sa.h>
#include <re_net.h>
#include <re_srtp.h>
#include <re_sys.h>
#include <re_tcp.h>
Expand Down
2 changes: 1 addition & 1 deletion src/tls/openssl/tls_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include <re_fmt.h>
#include <re_mem.h>
#include <re_mbuf.h>
#include <re_net.h>
#include <re_main.h>
#include <re_sa.h>
#include <re_net.h>
#include <re_srtp.h>
#include <re_tcp.h>
#include <re_tls.h>
Expand Down
2 changes: 1 addition & 1 deletion src/udp/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#include <re_mem.h>
#include <re_mbuf.h>
#include <re_list.h>
#include <re_net.h>
#include <re_main.h>
#include <re_sa.h>
#include <re_net.h>
#include <re_udp.h>
#ifdef WIN32
#if !defined(_MSC_VER)
Expand Down

0 comments on commit f9479bf

Please sign in to comment.