Skip to content

Commit 233a4d5

Browse files
committed
Fix #12, support sendmmsg for UDP
1 parent 91d530e commit 233a4d5

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ OTHER_FLAGS = -Wall
189189
ifeq ($(shell test -f /usr/include/sys/epoll.h && echo yes), yes)
190190
DEFINES += -DMD_HAVE_EPOLL
191191
endif
192+
# For SRS, sendmmsg
193+
ifeq ($(shell grep -qs sendmmsg /usr/include/sys/socket.h && echo yes), yes)
194+
DEFINES += -DMD_HAVE_SENDMMSG -D_GNU_SOURCE
195+
endif
192196
endif
193197

194198
ifeq ($(OS), NETBSD)
@@ -282,6 +286,10 @@ endif
282286
#
283287
# make EXTRA_CFLAGS=-UMD_HAVE_EPOLL <target>
284288
#
289+
# or to enable sendmmsg(2) support:
290+
#
291+
# make EXTRA_CFLAGS="-DMD_HAVE_SENDMMSG -D_GNU_SOURCE"
292+
#
285293
##########################
286294

287295
CFLAGS += $(DEFINES) $(OTHER_FLAGS) $(EXTRA_CFLAGS)

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The branch [srs](https://github.com/ossrs/state-threads/tree/srs) will be patche
2323
- [x] Support macro `MD_ST_NO_ASM` to disable ASM, [#8](https://github.com/ossrs/state-threads/issues/8).
2424
- [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).
2525
- [x] Support OSX for Apple Darwin, macOS, [#11](https://github.com/ossrs/state-threads/issues/11).
26+
- [x] Support sendmmsg for UDP, [#12](https://github.com/ossrs/state-threads/issues/12).
2627

2728
## Docs
2829

@@ -86,4 +87,10 @@ Important cli options:
8687
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.
8788
1. `--show-reachable=<yes|no> , --show-possibly-lost=<yes|no>`, to show the using memory.
8889

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

io.c

+32
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,38 @@ int st_sendmsg(_st_netfd_t *fd, const struct msghdr *msg, int flags, st_utime_t
743743
}
744744

745745

746+
#if defined(MD_HAVE_SENDMMSG) && defined(_GNU_SOURCE)
747+
int st_sendmmsg(st_netfd_t fd, struct mmsghdr *msgvec, unsigned int vlen, int flags, st_utime_t timeout)
748+
{
749+
int n;
750+
int left;
751+
struct mmsghdr *p;
752+
753+
left = (int)vlen;
754+
while (left > 0) {
755+
p = msgvec + (vlen - left);
756+
757+
if ((n = sendmmsg(fd->osfd, p, left, flags)) < 0) {
758+
if (errno == EINTR)
759+
continue;
760+
if (!_IO_NOT_READY_ERROR)
761+
break;
762+
/* Wait until the socket becomes writable */
763+
if (st_netfd_poll(fd, POLLOUT, timeout) < 0)
764+
break;
765+
}
766+
767+
left -= n;
768+
}
769+
770+
// An error is returned only if no datagrams could be sent.
771+
if (left == (int)vlen) {
772+
return n;
773+
}
774+
return (int)vlen - left;
775+
}
776+
#endif
777+
746778

747779
/*
748780
* To open FIFOs or other special files.

public.h

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ extern int st_recvfrom(st_netfd_t fd, void *buf, int len, struct sockaddr *from,
151151
extern int st_sendto(st_netfd_t fd, const void *msg, int len, const struct sockaddr *to, int tolen, st_utime_t timeout);
152152
extern int st_recvmsg(st_netfd_t fd, struct msghdr *msg, int flags, st_utime_t timeout);
153153
extern int st_sendmsg(st_netfd_t fd, const struct msghdr *msg, int flags, st_utime_t timeout);
154+
extern int st_sendmmsg(st_netfd_t fd, struct mmsghdr *msgvec, unsigned int vlen, int flags, st_utime_t timeout);
154155
extern st_netfd_t st_open(const char *path, int oflags, mode_t mode);
155156

156157
#ifdef DEBUG

0 commit comments

Comments
 (0)