Skip to content
This repository has been archived by the owner on Feb 18, 2023. It is now read-only.

sa,unixsock: add unix domain socket support #159

Merged
merged 5 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ set(SRCS
src/trice.c
src/turn.c
src/udp.c
src/unixsock.c
src/uri.c
src/vid.c
src/vidconv.c
Expand Down
6 changes: 6 additions & 0 deletions src/sa.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ int test_sa_cmp(void)
uint16_t port2;
bool eq;
} testv[] = {
{
"unix:/test.sock", 0,
"unix:/test.sock", 0,
true
},
{
"1.2.3.4", 12345,
"1.2.3.4", 12345,
Expand Down Expand Up @@ -336,6 +341,7 @@ int test_sa_pton(void)
{"fa01::2a29", 0 },
{"127.0.0.1", 0 },
{"192.168.110.2", 0 },
{"unix:/test.sock", 0 },
{"fe80::xxxx:d8d9:ddc3:25dd:%eth0", EADDRNOTAVAIL},
};

Expand Down
1 change: 1 addition & 0 deletions src/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ static const struct test tests[] = {
TEST(test_turn),
TEST(test_turn_tcp),
TEST(test_udp),
TEST(test_unixsock),
TEST(test_uri),
TEST(test_uri_encode),
TEST(test_uri_headers),
Expand Down
1 change: 1 addition & 0 deletions src/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ int test_try_into(void);
int test_turn(void);
int test_turn_tcp(void);
int test_udp(void);
int test_unixsock(void);
int test_uri(void);
int test_uri_encode(void);
int test_uri_headers(void);
Expand Down
60 changes: 60 additions & 0 deletions src/unixsock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @file src/unixsock.c Unix domain sockets
*
* Copyright (C) 2022 Sebastian Reimers
*/

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <re.h>
#include "test.h"
#ifdef WIN32
#define unlink _unlink
#endif

#define DEBUG_MODULE "unixsock"
#define DEBUG_LEVEL 5
#include <re_dbg.h>


static void http_req_handler(struct http_conn *conn,
const struct http_msg *msg, void *arg)
{
(void)conn;
(void)msg;
(void)arg;
}


int test_unixsock(void)
{
struct sa srv;
re_sock_t fd = RE_BAD_SOCK;
struct http_sock *sock;
int err;
char filename[32];
char socket[128];

rand_str(filename, sizeof(filename));
re_snprintf(socket, sizeof(socket), "unix:http_%s.sock", filename);

err = sa_set_str(&srv, socket, 0);
TEST_ERR(err);

err = unixsock_listen_fd(&fd, &srv);
TEST_ERR(err);

err = http_listen_fd(&sock, fd, http_req_handler, NULL);
TEST_ERR(err);

mem_deref(sock);

err = unlink(&socket[5]);
TEST_ERR(err);

out:
if (err)
(void)unlink(&socket[5]);
return err;
}