net: encapsulate fdwatch backend metadata
This commit is contained in:
@@ -37,6 +37,10 @@ bool CNetPoller::Create()
|
||||
return false;
|
||||
}
|
||||
|
||||
sys_log(0, "[STARTUP] fdwatch backend=%s descriptor_limit=%d",
|
||||
fdwatch_backend_name(fdwatch_get_backend(m_fdWatcher)),
|
||||
fdwatch_get_descriptor_limit(m_fdWatcher));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -602,6 +602,16 @@ int start(int argc, char **argv)
|
||||
|
||||
main_fdw = fdwatch_new(4096);
|
||||
|
||||
if (!main_fdw)
|
||||
{
|
||||
sys_err("fdwatch_new failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
sys_log(0, "[STARTUP] fdwatch backend=%s descriptor_limit=%d",
|
||||
fdwatch_backend_name(fdwatch_get_backend(main_fdw)),
|
||||
fdwatch_get_descriptor_limit(main_fdw));
|
||||
|
||||
if ((tcp_socket = socket_tcp_bind(g_szPublicIP, mother_port)) == INVALID_SOCKET)
|
||||
{
|
||||
perror("socket_tcp_bind: tcp_socket");
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef __USE_SELECT__
|
||||
|
||||
typedef struct fdwatch FDWATCH;
|
||||
typedef struct fdwatch * LPFDWATCH;
|
||||
|
||||
@@ -14,62 +12,12 @@
|
||||
FDW_EOF = 8,
|
||||
};
|
||||
|
||||
typedef struct kevent KEVENT;
|
||||
typedef struct kevent * LPKEVENT;
|
||||
typedef int KQUEUE;
|
||||
|
||||
struct fdwatch
|
||||
enum EFdwatchBackend
|
||||
{
|
||||
KQUEUE kq;
|
||||
|
||||
int nfiles;
|
||||
|
||||
LPKEVENT kqevents;
|
||||
int nkqevents;
|
||||
|
||||
LPKEVENT kqrevents;
|
||||
int * fd_event_idx;
|
||||
|
||||
void ** fd_data;
|
||||
int * fd_rw;
|
||||
FDWATCH_BACKEND_KQUEUE = 0,
|
||||
FDWATCH_BACKEND_SELECT = 1,
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
typedef struct fdwatch FDWATCH;
|
||||
typedef struct fdwatch * LPFDWATCH;
|
||||
|
||||
enum EFdwatch
|
||||
{
|
||||
FDW_NONE = 0,
|
||||
FDW_READ = 1,
|
||||
FDW_WRITE = 2,
|
||||
FDW_WRITE_ONESHOT = 4,
|
||||
FDW_EOF = 8,
|
||||
};
|
||||
|
||||
struct fdwatch
|
||||
{
|
||||
fd_set rfd_set;
|
||||
fd_set wfd_set;
|
||||
|
||||
socket_t* select_fds;
|
||||
int* select_rfdidx;
|
||||
|
||||
int nselect_fds;
|
||||
|
||||
fd_set working_rfd_set;
|
||||
fd_set working_wfd_set;
|
||||
|
||||
int nfiles;
|
||||
|
||||
void** fd_data;
|
||||
int* fd_rw;
|
||||
};
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
|
||||
LPFDWATCH fdwatch_new(int nfiles);
|
||||
void fdwatch_clear_fd(LPFDWATCH fdw, socket_t fd);
|
||||
void fdwatch_delete(LPFDWATCH fdw);
|
||||
@@ -82,4 +30,6 @@ void * fdwatch_get_client_data(LPFDWATCH fdw, unsigned int event_idx);
|
||||
void fdwatch_del_fd(LPFDWATCH fdw, socket_t fd);
|
||||
int fdwatch_get_buffer_size(LPFDWATCH fdw, socket_t fd);
|
||||
int fdwatch_get_ident(LPFDWATCH fdw, unsigned int event_idx);
|
||||
|
||||
EFdwatchBackend fdwatch_get_backend(LPFDWATCH fdw);
|
||||
const char * fdwatch_backend_name(EFdwatchBackend backend);
|
||||
int fdwatch_get_descriptor_limit(LPFDWATCH fdw);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
@@ -289,6 +290,24 @@ void TestFdwatchReadAndOneshotWrite()
|
||||
close(sockets[0]);
|
||||
close(sockets[1]);
|
||||
}
|
||||
|
||||
void TestFdwatchBackendMetadata()
|
||||
{
|
||||
LPFDWATCH fdw = fdwatch_new(4096);
|
||||
Expect(fdw != nullptr, "fdwatch_new for backend metadata failed");
|
||||
|
||||
#ifdef __USE_SELECT__
|
||||
Expect(fdwatch_get_backend(fdw) == FDWATCH_BACKEND_SELECT, "Expected select backend");
|
||||
Expect(std::strcmp(fdwatch_backend_name(fdwatch_get_backend(fdw)), "select") == 0, "Unexpected select backend name");
|
||||
Expect(fdwatch_get_descriptor_limit(fdw) == std::min(4096, static_cast<int>(FD_SETSIZE)), "Unexpected select descriptor limit");
|
||||
#else
|
||||
Expect(fdwatch_get_backend(fdw) == FDWATCH_BACKEND_KQUEUE, "Expected kqueue backend");
|
||||
Expect(std::strcmp(fdwatch_backend_name(fdwatch_get_backend(fdw)), "kqueue") == 0, "Unexpected kqueue backend name");
|
||||
Expect(fdwatch_get_descriptor_limit(fdw) == 4096, "Unexpected kqueue descriptor limit");
|
||||
#endif
|
||||
|
||||
fdwatch_delete(fdw);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -298,6 +317,7 @@ int main()
|
||||
TestPacketLayouts();
|
||||
TestSecureCipherRoundTrip();
|
||||
TestSocketAuthWireFlow();
|
||||
TestFdwatchBackendMetadata();
|
||||
TestFdwatchReadAndOneshotWrite();
|
||||
std::cout << "metin smoke tests passed\n";
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user