Progress
This commit is contained in:
+2
-2
@@ -820,7 +820,7 @@ int chunk_server_free(ChunkServer *state)
|
||||
int chunk_server_step(ChunkServer *state, void **contexts, struct pollfd *polled, int num_polled)
|
||||
{
|
||||
Event events[MAX_CONNS+1];
|
||||
int num_events = tcp_translate_events(&state->tcp, contexts, polled, num_polled, events);
|
||||
int num_events = tcp_translate_events(&state->tcp, events, contexts, polled, num_polled);
|
||||
|
||||
Time current_time = get_current_time();
|
||||
if (current_time == INVALID_TIME)
|
||||
@@ -938,5 +938,5 @@ int chunk_server_step(ChunkServer *state, void **contexts, struct pollfd *polled
|
||||
}
|
||||
}
|
||||
|
||||
return tcp_register_events(&state->tcp, contexts, polled, num_polled);
|
||||
return tcp_register_events(&state->tcp, contexts, polled);
|
||||
}
|
||||
|
||||
+10
-2
@@ -2,8 +2,16 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "core/chunk_server.h"
|
||||
#include "core/metadata_server.h"
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#define POLL WSAPoll
|
||||
#else
|
||||
#include <poll.h>
|
||||
#define POLL poll
|
||||
#endif
|
||||
|
||||
#include "chunk_server.h"
|
||||
#include "metadata_server.h"
|
||||
|
||||
int metadata_server_main(int argc, char **argv)
|
||||
{
|
||||
|
||||
+28
-5
@@ -1,10 +1,18 @@
|
||||
#ifdef BUILD_TEST
|
||||
|
||||
#include "core/chunk_server.h"
|
||||
#include "core/metadata_server.h"
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "chunk_server.h"
|
||||
#include "metadata_server.h"
|
||||
|
||||
#define MAX_PROCESSES 128
|
||||
#define MAX_DESCRIPTORS 1024
|
||||
#define MAX_ALLOCATIONS 128
|
||||
|
||||
typedef enum {
|
||||
DESCRIPTOR_TYPE_EMPTY,
|
||||
@@ -128,7 +136,7 @@ void descriptor_turn_socket_into_listener(Descriptor *desc, int backlog)
|
||||
|
||||
void descriptor_turn_socket_into_connection(Descriptor *desc, int peer_process, int peer_fd)
|
||||
{
|
||||
desc->type = DESCRIPTOR_TYPE_LISTENER_SOCKET;
|
||||
desc->type = DESCRIPTOR_TYPE_CONNECTION_SOCKET;
|
||||
desc->pending = true;
|
||||
desc->peer_process = peer_process;
|
||||
desc->peer_fd = peer_fd;
|
||||
@@ -151,7 +159,7 @@ void descriptor_free(Descriptor *desc)
|
||||
break;
|
||||
|
||||
case DESCRIPTOR_TYPE_FILE:
|
||||
close(desc->proxy_fd);
|
||||
close(desc->real_fd);
|
||||
break;
|
||||
|
||||
case DESCRIPTOR_TYPE_SOCKET:
|
||||
@@ -367,6 +375,16 @@ void sys_free_(void *ptr, char *file, int line)
|
||||
current_process->at->allocs[found] = current_process->at->allocs[--current_process->num_allocs];
|
||||
}
|
||||
|
||||
int sys_remove(char *path)
|
||||
{
|
||||
return remove(path);
|
||||
}
|
||||
|
||||
int sys_rename(char *oldpath, char *newpath)
|
||||
{
|
||||
return rename(oldpath, newpath);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
SOCKET sys_socket(int domain, int type, int protocol)
|
||||
@@ -931,7 +949,7 @@ int sys_write(int fd, char *src, int len)
|
||||
}
|
||||
}
|
||||
|
||||
int sys_stat(int fd, struct stat *buf)
|
||||
int sys_fstat(int fd, struct stat *buf)
|
||||
{
|
||||
Descriptor *desc = ¤t_process->dt->desc[fd];
|
||||
if (desc->type != DESCRIPTOR_TYPE_FILE) {
|
||||
@@ -952,6 +970,11 @@ char* sys_realpath(char *path, char *dst)
|
||||
return realpath(path, dst);
|
||||
}
|
||||
|
||||
int sys_mkdir(char *path, mode_t mode)
|
||||
{
|
||||
return mkdir(path, mode);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // BUILD_TEST
|
||||
|
||||
@@ -48,7 +48,7 @@ typedef struct {
|
||||
|
||||
} MetadataServer;
|
||||
|
||||
int metadata_server_init(MetadataServer *state, int argc, char **argv);
|
||||
int metadata_server_init(MetadataServer *state, int argc, char **argv, void **contexts, struct pollfd *polled);
|
||||
int metadata_server_free(MetadataServer *state);
|
||||
int metadata_server_step(MetadataServer *state, void **contexts, struct pollfd *polled, int num_polled);
|
||||
|
||||
|
||||
+28
-18
@@ -1,3 +1,8 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/file.h>
|
||||
|
||||
#include "system.h"
|
||||
|
||||
void *sys_malloc_(size_t len, char *file, int line)
|
||||
@@ -21,6 +26,16 @@ void sys_free_(void *ptr, char *file, int line)
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
int sys_remove(char *path)
|
||||
{
|
||||
return remove(path);
|
||||
}
|
||||
|
||||
int sys_rename(char *oldpath, char *newpath)
|
||||
{
|
||||
return rename(oldpath, newpath);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
SOCKET sys_socket(int domain, int type, int protocol)
|
||||
@@ -43,11 +58,6 @@ int sys_closesocket(SOCKET fd)
|
||||
return closesocket(fd);
|
||||
}
|
||||
|
||||
int sys_WSAPoll(struct pollfd *polled, int num_polled, int timeout)
|
||||
{
|
||||
return WSAPoll(polled, num_polled, timeout);
|
||||
}
|
||||
|
||||
SOCKET sys_accept(SOCKET fd, void *addr, int *addr_len)
|
||||
{
|
||||
return accept(fd, addr, addr_len);
|
||||
@@ -150,17 +160,7 @@ int sys_listen(int fd, int backlog)
|
||||
return listen(fd, backlog);
|
||||
}
|
||||
|
||||
int sys_close(int fd)
|
||||
{
|
||||
return close(fd);
|
||||
}
|
||||
|
||||
int sys_poll(struct pollfd *polled, int num_polled, int timeout)
|
||||
{
|
||||
return poll(polled, num_polled, timeout);
|
||||
}
|
||||
|
||||
int sys_accept(int fd, void *addr, int *addr_len)
|
||||
int sys_accept(int fd, void *addr, socklen_t *addr_len)
|
||||
{
|
||||
return accept(fd, addr, addr_len);
|
||||
}
|
||||
@@ -220,9 +220,14 @@ int sys_read(int fd, char *dst, int len)
|
||||
return read(fd, dst, len);
|
||||
}
|
||||
|
||||
int sys_stat(int fd, struct stat *buf)
|
||||
int sys_write(int fd, char *src, int len)
|
||||
{
|
||||
return stat(fd, buf);
|
||||
return write(fd, src, len);
|
||||
}
|
||||
|
||||
int sys_fstat(int fd, struct stat *buf)
|
||||
{
|
||||
return fstat(fd, buf);
|
||||
}
|
||||
|
||||
int sys_mkstemp(char *path)
|
||||
@@ -235,4 +240,9 @@ char* sys_realpath(char *path, char *dst)
|
||||
return realpath(path, dst);
|
||||
}
|
||||
|
||||
int sys_mkdir(char *path, mode_t mode)
|
||||
{
|
||||
return mkdir(path, mode);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+18
-18
@@ -1,3 +1,4 @@
|
||||
#include <stddef.h>
|
||||
|
||||
void *sys_malloc_ (size_t len, char *file, int line);
|
||||
void *sys_realloc_(void *ptr, size_t len, char *file, int line);
|
||||
@@ -7,24 +8,14 @@ void sys_free_ (void *ptr, char *file, int line);
|
||||
#define sys_realloc(ptr, len) sys_realloc_((ptr), (len), __FILE__, __LINE__)
|
||||
#define sys_free(ptr) sys_free_ ((ptr), __FILE__, __LINE__)
|
||||
|
||||
int sys_remove(char *path);
|
||||
int sys_rename(char *oldpath, char *newpath);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
typedef union _LARGE_INTEGER {
|
||||
struct {
|
||||
DWORD LowPart;
|
||||
LONG HighPart;
|
||||
} DUMMYSTRUCTNAME;
|
||||
struct {
|
||||
DWORD LowPart;
|
||||
LONG HighPart;
|
||||
} u;
|
||||
LONGLONG QuadPart;
|
||||
} LARGE_INTEGER;
|
||||
|
||||
#define BOOL int
|
||||
#define WCHAR wchar_t
|
||||
#define SOCKET void*
|
||||
#define HANDLE void*
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
|
||||
SOCKET sys_socket (int domain, int type, int protocol);
|
||||
int sys_bind (SOCKET fd, void *addr, size_t addr_len);
|
||||
@@ -50,10 +41,17 @@ char* sys__fullpath (char *path, char *dst, int cap);
|
||||
|
||||
#else
|
||||
|
||||
#include <poll.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
int sys_socket (int domain, int type, int protocol);
|
||||
int sys_bind (int fd, void *addr, size_t addr_len);
|
||||
int sys_listen (int fd, int backlog);
|
||||
int sys_accept (int fd, void *addr, int *addr_len);
|
||||
int sys_accept (int fd, void *addr, socklen_t *addr_len);
|
||||
int sys_getsockopt (int fd, int level, int optname, void *optval, socklen_t *optlen);
|
||||
int sys_setsockopt (int fd, int level, int optname, void *optval, socklen_t optlen);
|
||||
int sys_recv (int fd, void *dst, int len, int flags);
|
||||
@@ -65,8 +63,10 @@ int sys_close (int fd);
|
||||
int sys_flock (int fd, int op);
|
||||
int sys_fsync (int fd);
|
||||
int sys_read (int fd, char *dst, int len);
|
||||
int sys_stat (int fd, struct stat *buf);
|
||||
int sys_write (int fd, char *src, int len);
|
||||
int sys_fstat (int fd, struct stat *buf);
|
||||
int sys_mkstemp (char *path);
|
||||
char* sys_realpath (char *path, char *dst);
|
||||
int sys_mkdir (char *path, mode_t mode);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -59,7 +59,7 @@ static void conn_init(Connection *conn, SOCKET fd, bool connecting)
|
||||
|
||||
static void conn_free(Connection *conn)
|
||||
{
|
||||
sys_closesocket(conn->fd);
|
||||
CLOSE_SOCKET(conn->fd);
|
||||
byte_queue_free(&conn->input);
|
||||
byte_queue_free(&conn->output);
|
||||
}
|
||||
@@ -91,7 +91,7 @@ void tcp_context_init(TCP *tcp)
|
||||
void tcp_context_free(TCP *tcp)
|
||||
{
|
||||
if (tcp->listen_fd != INVALID_SOCKET)
|
||||
sys_closesocket(tcp->listen_fd);
|
||||
CLOSE_SOCKET(tcp->listen_fd);
|
||||
}
|
||||
|
||||
int tcp_index_from_tag(TCP *tcp, int tag)
|
||||
@@ -307,7 +307,7 @@ int tcp_connect(TCP *tcp, Address addr, int tag, ByteQueue **output)
|
||||
connecting = false;
|
||||
} else {
|
||||
if (errno != EINPROGRESS) {
|
||||
sys_closesocket(fd);
|
||||
CLOSE_SOCKET(fd);
|
||||
return -1;
|
||||
}
|
||||
connecting = true;
|
||||
|
||||
Reference in New Issue
Block a user