diff --git a/emper/c_emper.cpp b/emper/c_emper.cpp index 4e2a47184d72015f7853ba5d57b872954c68b0d0..667651448847f12cd49eb470597ceb6037a4cac5 100644 --- a/emper/c_emper.cpp +++ b/emper/c_emper.cpp @@ -5,6 +5,10 @@ #include "BinaryPrivateSemaphore.hpp" #include "CountingPrivateSemaphore.hpp" +#ifdef EMPER_ASYNC_LIB +#include "AsyncLibrary.hpp" +#endif + runtime* init_runtime(void) { Runtime* r = new Runtime(); return reinterpret_cast<runtime*>(r); @@ -96,3 +100,39 @@ void wait_cps(cps* sem) { countingPrivateSemaphore->wait(); } +#ifdef EMPER_ASYNC_NETWORK +int async_recv(int fd, unsigned char* buff, int buff_len, int flags) { + bool read_once = flags & READ_FULL_BUFFER == 0; + bool fd_serialized = flags & UNSERIALIZED == 0; + + return io::async_recv(fd, buff, buff_len, read_once, fd_serialized); +} + +int async_send(int fd, unsigned char* buff, int buff_len, int flags) { + bool fd_serialized = flags & UNSERIALIZED == 0; + + return io::async_recv(fd, buff, buff_len, read_once, fd_serialized); +} + +int async_connect(int fd, sockaddr* sockaddress, socklen_t len, int flags) { + bool fd_serialized = flags & UNSERIALIZED == 0; + + return io::async_connect(fd, sockaddress, len, fd_serialized); +} + +int async_accept(int fd, sockaddr* sockaddress, socklen_t len, int flags) { + bool fd_serialized = flags & UNSERIALIZED == 0; + + return io::async_accept(fd, sockaddress, len, fd_serialized); +} +#endif + +#ifdef EMPER_ASYNC_DISK_IO +int async_read_file(int fd, unsigned char* buff, size_t count, off_t offset) { + return io::async_read_file(fd, buff, count, offset); +} + +int async_write_file(int fd, const unsigned char* buff, size_t count, off_t offset) { + return io::async_write_file(fd, buff, count, offset); +} +#endif diff --git a/emper/include/emper.h b/emper/include/emper.h index 981850c50dad7d05bbc5d98244a982c8933c123b..11393ef3efe854f98f5d391855539f4280709de6 100644 --- a/emper/include/emper.h +++ b/emper/include/emper.h @@ -2,6 +2,10 @@ #include "emper-common.h" +#ifdef EMPER_ASYNC_NETWORK +#include "sys/socket.h" +#endif + typedef struct runtime runtime; typedef struct fiber fiber; @@ -56,6 +60,27 @@ extern "C" { void wait_cps(cps* sem); +#ifdef EMPER_ASYNC_NETWORK + enum EMPER_ASYNC_NETWORK_FLAGS { + READ_FULL_BUFFER = 1, + UNSERIALIZED = 2, + }; + + int async_recv(int fd, unsigned char* buff, int buff_len, int flags); + + int async_send(int fd, unsigned char* buff, int buff_len, int flags); + + int async_connect(int fd, sockaddr* sockaddress, socklen_t len, int flags); + + int async_accept(int fd, sockaddr* sockaddress, socklen_t len, int flags); +#endif + +#ifdef EMPER_ASYNC_DISK_IO + int async_read_file(int fd, unsigned char* buff, size_t count, off_t offset); + + int async_write_file(int fd, const unsigned char* buff, size_t count, off_t offset); +#endif + #ifdef __cplusplus } #endif