Skip to content

Commit

Permalink
Fix #12, support sendmmsg for UDP
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Apr 18, 2020
1 parent 91d530e commit 233a4d5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ OTHER_FLAGS = -Wall
ifeq ($(shell test -f /usr/include/sys/epoll.h && echo yes), yes)
DEFINES += -DMD_HAVE_EPOLL
endif
# For SRS, sendmmsg
ifeq ($(shell grep -qs sendmmsg /usr/include/sys/socket.h && echo yes), yes)
DEFINES += -DMD_HAVE_SENDMMSG -D_GNU_SOURCE
endif
endif

ifeq ($(OS), NETBSD)
Expand Down Expand Up @@ -282,6 +286,10 @@ endif
#
# make EXTRA_CFLAGS=-UMD_HAVE_EPOLL <target>
#
# or to enable sendmmsg(2) support:
#
# make EXTRA_CFLAGS="-DMD_HAVE_SENDMMSG -D_GNU_SOURCE"
#
##########################

CFLAGS += $(DEFINES) $(OTHER_FLAGS) $(EXTRA_CFLAGS)
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The branch [srs](https://github.com/ossrs/state-threads/tree/srs) will be patche
- [x] Support macro `MD_ST_NO_ASM` to disable ASM, [#8](https://github.com/ossrs/state-threads/issues/8).
- [x] Merge patch [srs#1282](https://github.com/ossrs/srs/issues/1282#issuecomment-445539513) to support aarch64, [#9](https://github.com/ossrs/state-threads/issues/9).
- [x] Support OSX for Apple Darwin, macOS, [#11](https://github.com/ossrs/state-threads/issues/11).
- [x] Support sendmmsg for UDP, [#12](https://github.com/ossrs/state-threads/issues/12).

## Docs

Expand Down Expand Up @@ -86,4 +87,10 @@ Important cli options:
1. `--track-origins=<yes|no> [default: no]`, Controls whether Memcheck tracks the origin of uninitialised values. By default, it does not, which means that although it can tell you that an uninitialised value is being used in a dangerous way, it cannot tell you where the uninitialised value came from. This often makes it difficult to track down the root problem.
1. `--show-reachable=<yes|no> , --show-possibly-lost=<yes|no>`, to show the using memory.

## Analysis

1. About setjmp and longjmp, read [setjmp](https://gitee.com/winlinvip/srs-wiki/raw/master/images/st-setjmp.jpg).
1. About the stack structure, read [stack](https://gitee.com/winlinvip/srs-wiki/raw/master/images/st-stack.jpg)
1. About asm code comments, read [#91d530e](https://github.com/ossrs/state-threads/commit/91d530e#diff-ed9428b14ff6afda0e9ab04cc91d4445R25).

Winlin 2016
32 changes: 32 additions & 0 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,38 @@ int st_sendmsg(_st_netfd_t *fd, const struct msghdr *msg, int flags, st_utime_t
}


#if defined(MD_HAVE_SENDMMSG) && defined(_GNU_SOURCE)
int st_sendmmsg(st_netfd_t fd, struct mmsghdr *msgvec, unsigned int vlen, int flags, st_utime_t timeout)
{
int n;
int left;
struct mmsghdr *p;

left = (int)vlen;
while (left > 0) {
p = msgvec + (vlen - left);

if ((n = sendmmsg(fd->osfd, p, left, flags)) < 0) {
if (errno == EINTR)
continue;
if (!_IO_NOT_READY_ERROR)
break;
/* Wait until the socket becomes writable */
if (st_netfd_poll(fd, POLLOUT, timeout) < 0)
break;
}

left -= n;
}

// An error is returned only if no datagrams could be sent.
if (left == (int)vlen) {
return n;
}
return (int)vlen - left;
}
#endif


/*
* To open FIFOs or other special files.
Expand Down
1 change: 1 addition & 0 deletions public.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ extern int st_recvfrom(st_netfd_t fd, void *buf, int len, struct sockaddr *from,
extern int st_sendto(st_netfd_t fd, const void *msg, int len, const struct sockaddr *to, int tolen, st_utime_t timeout);
extern int st_recvmsg(st_netfd_t fd, struct msghdr *msg, int flags, st_utime_t timeout);
extern int st_sendmsg(st_netfd_t fd, const struct msghdr *msg, int flags, st_utime_t timeout);
extern int st_sendmmsg(st_netfd_t fd, struct mmsghdr *msgvec, unsigned int vlen, int flags, st_utime_t timeout);
extern st_netfd_t st_open(const char *path, int oflags, mode_t mode);

#ifdef DEBUG
Expand Down

0 comments on commit 233a4d5

Please sign in to comment.