Skip to content

Commit d9d27fc

Browse files
committed
Support musl build
2 parents baad248 + 488c83c commit d9d27fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+375
-364
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ Websocket server that complies with RFC6455.(The WebSocket Protocol)
1515
```shell
1616
# release build
1717
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
18+
cmake --build build
1819
make BUILD=release -C examples/echoback
1920

2021
# debug build
2122
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
23+
cmake --build build
2224
make BUILD=debug -C examples/echoback
2325
```
2426

src/arch/accept.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#ifndef NOSTR_INTERNAL_ACCEPT_H_
22
#define NOSTR_INTERNAL_ACCEPT_H_
33

4+
#include "../util/types.h"
45
#ifdef __APPLE__
56
#include "darwin/accept.h"
67
#else
78
#include "linux/x86_64/accept.h"
89
#endif
910

10-
static inline int internal_accept(const int sock_fd, struct sockaddr* addr, socklen_t* addrlen, const int flags)
11+
static inline int32_t internal_accept(const int32_t sock_fd, struct sockaddr* addr, socklen_t* addrlen, const int32_t flags)
1112
{
1213
#ifdef __APPLE__
1314
return darwin_accept(sock_fd, addr, addrlen, flags);

src/arch/close.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#ifndef NOSTR_INTERNAL_CLOSE_H_
22
#define NOSTR_INTERNAL_CLOSE_H_
33

4+
#include "../util/types.h"
45
#ifdef __APPLE__
56
#include "darwin/close.h"
67
#else
78
#include "linux/x86_64/close.h"
89
#endif
910

10-
static inline int internal_close(int fd)
11+
static inline int32_t internal_close(int32_t fd)
1112
{
1213
#ifdef __APPLE__
1314
return darwin_close(fd);

src/arch/darwin/accept.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
#include <netinet/in.h>
55

6-
static inline int darwin_accept(const int sock_fd, struct sockaddr* addr, socklen_t* addrlen, const int flags)
6+
#include "../../util/types.h"
7+
8+
static inline int32_t darwin_accept(const int32_t sock_fd, struct sockaddr* addr, socklen_t* addrlen, const int32_t flags)
79
{
810
return accept(sock_fd, addr, addrlen);
911
}

src/arch/darwin/close.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
#include <unistd.h>
55

6-
static inline int darwin_close(int fd)
6+
#include "../../util/types.h"
7+
8+
static inline int32_t darwin_close(int32_t fd)
79
{
810
return close(fd);
911
}

src/arch/darwin/kqueue.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
#include <errno.h>
44
#include <netinet/in.h>
55
#include <stdbool.h>
6+
#include <stdint.h>
67
#include <string.h>
78
#include <sys/event.h>
89
#include <sys/syscall.h>
910
#include <time.h>
1011

1112
#include "../../util/signal.h"
13+
#include "../../util/types.h"
1214
#include "../../websocket/websocket_local.h"
1315
#include "./epoll.h"
1416

15-
bool websocket_epoll_add(const int epoll_fd, const int sock_fd, PWebSocketEpollEvent event)
17+
bool websocket_epoll_add(const int32_t epoll_fd, const int32_t sock_fd, PWebSocketEpollEvent event)
1618
{
1719
EV_SET(event, sock_fd, EVFILT_READ, EV_ADD, 0, 0, NULL);
1820

@@ -35,7 +37,7 @@ bool websocket_epoll_add(const int epoll_fd, const int sock_fd, PWebSocketEpollE
3537
return true;
3638
}
3739

38-
bool websocket_epoll_del(const int epoll_fd, const int sock_fd)
40+
bool websocket_epoll_del(const int32_t epoll_fd, const int32_t sock_fd)
3941
{
4042
struct kevent event;
4143
EV_SET(&event, sock_fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
@@ -48,9 +50,9 @@ bool websocket_epoll_del(const int epoll_fd, const int sock_fd)
4850
return true;
4951
}
5052

51-
int websocket_epoll_create()
53+
int32_t websocket_epoll_create()
5254
{
53-
int epoll_fd = kqueue();
55+
int32_t epoll_fd = kqueue();
5456
if (epoll_fd == -1) {
5557
str_error("Failed to kqueue(). reason : ", strerror(errno));
5658
return WEBSOCKET_ERRORCODE_FATAL_ERROR;
@@ -59,15 +61,15 @@ int websocket_epoll_create()
5961
return epoll_fd;
6062
}
6163

62-
int websocket_epoll_wait(const int epoll_fd, PWebSocketEpollEvent events, const int max_events)
64+
int32_t websocket_epoll_wait(const int32_t epoll_fd, PWebSocketEpollEvent events, const int32_t max_events)
6365
{
6466
if (is_rise_signal()) {
6567
log_info("A signal was raised during kevent(). The system will abort processing.\n");
6668
return WEBSOCKET_ERRORCODE_FATAL_ERROR;
6769
}
6870

6971
struct timespec timeout = {0, 0}; // Non-blocking
70-
int num_of_event = kevent(epoll_fd, NULL, 0, events, max_events, &timeout);
72+
int32_t num_of_event = kevent(epoll_fd, NULL, 0, events, max_events, &timeout);
7173

7274
if (num_of_event < 0) {
7375
if (errno == EINTR || errno == EAGAIN) {
@@ -82,12 +84,12 @@ int websocket_epoll_wait(const int epoll_fd, PWebSocketEpollEvent events, const
8284
return num_of_event;
8385
}
8486

85-
int websocket_epoll_getfd(PWebSocketEpollEvent event)
87+
int32_t websocket_epoll_getfd(PWebSocketEpollEvent event)
8688
{
8789
return event->ident;
8890
}
8991

90-
int websocket_epoll_rise_error(PWebSocketEpollEvent event)
92+
int32_t websocket_epoll_rise_error(PWebSocketEpollEvent event)
9193
{
9294
if (event->flags & EV_ERROR) {
9395
str_error("EV_ERROR : ", strerror((int)event->data));
@@ -97,7 +99,7 @@ int websocket_epoll_rise_error(PWebSocketEpollEvent event)
9799
return WEBSOCKET_ERRORCODE_NONE;
98100
}
99101

100-
int websocket_epoll_rise_input(PWebSocketEpollEvent event)
102+
int32_t websocket_epoll_rise_input(PWebSocketEpollEvent event)
101103
{
102104
if (!(event->filter | EVFILT_READ)) {
103105
return WEBSOCKET_ERRORCODE_CONTINUABLE_ERROR;

src/arch/darwin/listen.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22
#define NOSTR_DARWIN_LISTEN_H_
33

44
#include <sys/socket.h>
5-
#include <sys/types.h>
65

7-
static inline int darwin_socket(const int domain, const int type, const int protocol)
6+
#include "../../util/types.h"
7+
8+
static inline int32_t darwin_socket(const int32_t domain, const int32_t type, const int32_t protocol)
89
{
910
return socket(domain, type, protocol);
1011
}
1112

12-
static inline int darwin_bind(const int sockfd, const struct sockaddr* addr, const socklen_t addrlen)
13+
static inline int32_t darwin_bind(const int32_t sockfd, const struct sockaddr* addr, const socklen_t addrlen)
1314
{
1415
return bind(sockfd, addr, addrlen);
1516
}
1617

17-
static inline int darwin_listen(const int sockfd, const int backlog)
18+
static inline int32_t darwin_listen(const int32_t sockfd, const int32_t backlog)
1819
{
1920
return listen(sockfd, backlog);
2021
}

src/arch/darwin/memory.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
#include <string.h>
55

6+
#include "../../util/types.h"
7+
68
static inline void* darwin_memcpy(void* dest, const void* src, size_t size)
79
{
810
return memcpy(dest, src, size);
911
}
1012

11-
static inline void* darwin_memset(void* s, const int c, const size_t size)
13+
static inline void* darwin_memset(void* s, const int32_t c, const size_t size)
1214
{
1315
return memset(s, c, size);
1416
}
@@ -23,7 +25,7 @@ static inline void* darwin_memset(void* s, const int c, const size_t size)
2325
*
2426
* Note: A compiler barrier is inserted to ensure that the memset call is not optimized away.
2527
*/
26-
static inline int darwin_memset_s(void* s, const size_t smax, const int c, const size_t n)
28+
static inline int32_t darwin_memset_s(void* s, const size_t smax, const int32_t c, const size_t n)
2729
{
2830
return memset_s(s, smax, c, n);
2931
}

src/arch/darwin/optimize_socket.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
#include <netinet/in.h>
66
#include <netinet/tcp.h>
77

8-
static inline int darwin_fcntl(const int fd, const int cmd, const long arg)
8+
#include "../../util/types.h"
9+
10+
static inline int32_t darwin_fcntl(const int32_t fd, const int32_t cmd, const int64_t arg)
911
{
1012
return fcntl(fd, cmd, arg);
1113
}
1214

13-
static inline int darwin_setsockopt(
14-
const int sock_fd,
15-
const int level,
16-
const int optname,
15+
static inline int32_t darwin_setsockopt(
16+
const int32_t sock_fd,
17+
const int32_t level,
18+
const int32_t optname,
1719
const void* optval,
1820
const socklen_t optlen)
1921
{

src/arch/darwin/recv.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
#define NOSTR_DARWIN_RECV_H_
33

44
#include <sys/socket.h>
5-
#include <sys/types.h>
5+
6+
#include "../../util/types.h"
67

78
static inline ssize_t darwin_recvfrom(
8-
const int sock_fd,
9+
const int32_t sock_fd,
910
void* buf,
1011
const size_t len,
11-
const int flags,
12+
const int32_t flags,
1213
struct sockaddr* src_addr,
1314
socklen_t* addr_len)
1415
{

0 commit comments

Comments
 (0)