176404edcSAsim Jamshed #ifndef __MTCP_API_H_ 276404edcSAsim Jamshed #define __MTCP_API_H_ 376404edcSAsim Jamshed 476404edcSAsim Jamshed #include <stdint.h> 576404edcSAsim Jamshed #include <netinet/in.h> 676404edcSAsim Jamshed #include <sys/uio.h> 776404edcSAsim Jamshed 876404edcSAsim Jamshed #ifndef UNUSED 976404edcSAsim Jamshed #define UNUSED(x) (void)x 1076404edcSAsim Jamshed #endif 1176404edcSAsim Jamshed 1276404edcSAsim Jamshed #ifndef INPORT_ANY 1376404edcSAsim Jamshed #define INPORT_ANY (uint16_t)0 1476404edcSAsim Jamshed #endif 1576404edcSAsim Jamshed 1676404edcSAsim Jamshed typedef unsigned char byte; 1776404edcSAsim Jamshed 1876404edcSAsim Jamshed #ifdef __cplusplus 1976404edcSAsim Jamshed extern "C" { 2076404edcSAsim Jamshed #endif 2176404edcSAsim Jamshed 2276404edcSAsim Jamshed /** mTCP context */ 2376404edcSAsim Jamshed struct mtcp_context 2476404edcSAsim Jamshed { 2576404edcSAsim Jamshed int cpu; 2676404edcSAsim Jamshed }; 2776404edcSAsim Jamshed 2876404edcSAsim Jamshed typedef struct mtcp_context *mctx_t; 2976404edcSAsim Jamshed 3076404edcSAsim Jamshed /** mTCP signal handler type */ 3176404edcSAsim Jamshed typedef void (*mtcp_sighandler_t)(int); 3276404edcSAsim Jamshed 3376404edcSAsim Jamshed /** Socket types */ 3476404edcSAsim Jamshed enum socket_type 3576404edcSAsim Jamshed { 3676404edcSAsim Jamshed /** unused */ 3776404edcSAsim Jamshed MOS_SOCK_UNUSED, 3876404edcSAsim Jamshed 3976404edcSAsim Jamshed /* listening socket type */ 4076404edcSAsim Jamshed /** regular mTCP connection listen socket */ 4176404edcSAsim Jamshed MOS_SOCK_STREAM_LISTEN, 4276404edcSAsim Jamshed /** MOS proxy socket listening socket */ 4376404edcSAsim Jamshed /* (pending implementation) */ 4476404edcSAsim Jamshed MOS_SOCK_PROXY_LISTEN, 4576404edcSAsim Jamshed /** MOS monitor socket listening socket */ 4676404edcSAsim Jamshed MOS_SOCK_MONITOR_STREAM, 4776404edcSAsim Jamshed 4876404edcSAsim Jamshed /* stream socket type */ 4976404edcSAsim Jamshed 5076404edcSAsim Jamshed /** regular mTCP connection socket */ 5176404edcSAsim Jamshed MOS_SOCK_STREAM, 5276404edcSAsim Jamshed /** MOS proxy socket */ 5376404edcSAsim Jamshed /* (pending implementation) */ 5476404edcSAsim Jamshed MOS_SOCK_PROXY, 5576404edcSAsim Jamshed /** MOS monitor socket */ 5676404edcSAsim Jamshed MOS_SOCK_MONITOR_STREAM_ACTIVE, 5776404edcSAsim Jamshed /** MOS monitor socket (raw, stateless) */ 5876404edcSAsim Jamshed MOS_SOCK_MONITOR_RAW, 5976404edcSAsim Jamshed 6076404edcSAsim Jamshed /* for epoll */ 6176404edcSAsim Jamshed MOS_SOCK_EPOLL, 6276404edcSAsim Jamshed /* for pipe */ 6376404edcSAsim Jamshed MOS_SOCK_PIPE, 6476404edcSAsim Jamshed }; 6576404edcSAsim Jamshed 6676404edcSAsim Jamshed /* Configurable mTCP attributes 6776404edcSAsim Jamshed * This is automatically generated by mOS core after the 6876404edcSAsim Jamshed * mtcp_init() function call. You can change this option 6976404edcSAsim Jamshed * in your program using mtcp_get/set_conf(). 7076404edcSAsim Jamshed */ 7176404edcSAsim Jamshed struct mtcp_conf 7276404edcSAsim Jamshed { 7376404edcSAsim Jamshed /** Maximum length of application name */ 7476404edcSAsim Jamshed #define APP_NAME_LEN 40 7576404edcSAsim Jamshed /** Maximum concurrently runable application */ 7676404edcSAsim Jamshed #define MOS_APP 20 7776404edcSAsim Jamshed 7876404edcSAsim Jamshed int num_cores; /**< number of cores to use */ 7976404edcSAsim Jamshed int max_concurrency; /**< number of concurrent flows per core*/ 8076404edcSAsim Jamshed uint64_t cpu_mask; 8176404edcSAsim Jamshed 8276404edcSAsim Jamshed int max_num_buffers; /**< number of socket buffers */ 8376404edcSAsim Jamshed int rcvbuf_size; /**< size of receive buffer */ 8476404edcSAsim Jamshed int sndbuf_size; /**< size of send buffer */ 8576404edcSAsim Jamshed 8676404edcSAsim Jamshed int tcp_timewait; /**< time wait time in sec */ 8776404edcSAsim Jamshed int tcp_timeout; /**< timeout in sec, -1 for not to check timeout */ 8876404edcSAsim Jamshed 8976404edcSAsim Jamshed #define MOS_APP_ARGC 20 9076404edcSAsim Jamshed uint64_t app_cpu_mask[MOS_APP]; 9176404edcSAsim Jamshed char *app_argv[MOS_APP][MOS_APP_ARGC]; 9276404edcSAsim Jamshed int app_argc[MOS_APP]; 9376404edcSAsim Jamshed int num_app; /**< number of registered apps */ 9476404edcSAsim Jamshed }; 9576404edcSAsim Jamshed 9676404edcSAsim Jamshed /* Target to modify */ 9776404edcSAsim Jamshed struct app_context 9876404edcSAsim Jamshed { 9976404edcSAsim Jamshed mctx_t mctx; /**< mTCP context */ 10076404edcSAsim Jamshed int socket_id; /**< listing socket ID */ 10176404edcSAsim Jamshed struct conn_filter *cf; 10276404edcSAsim Jamshed int ep_id; 10376404edcSAsim Jamshed }; 10476404edcSAsim Jamshed 10576404edcSAsim Jamshed /* Application need to specify those parameters. */ 10676404edcSAsim Jamshed /* NOTE: This structure is not used in mos_release 0.2a 10776404edcSAsim Jamshed * This structure will be used by embedded mOS application using 10876404edcSAsim Jamshed * mOS server. 10976404edcSAsim Jamshed */ 11076404edcSAsim Jamshed struct app_ops 11176404edcSAsim Jamshed { 11276404edcSAsim Jamshed /** Initialization function which is called for only once per each 11376404edcSAsim Jamshed * application */ 11476404edcSAsim Jamshed void (*app_init)(int argc, char **argv); 11576404edcSAsim Jamshed /** Initialization function which is called for each CPU core */ 11676404edcSAsim Jamshed void (*thread_init)(mctx_t mctx, void **app_ctx); 11776404edcSAsim Jamshed /** Function contains code which will be executed after initialization 11876404edcSAsim Jamshed * phase */ 11976404edcSAsim Jamshed void (*run)(mctx_t mctx, void **app_ctx); 120*05e3289cSYoungGyoun /* is the application enabled at the moment? */ 121*05e3289cSYoungGyoun int enable; 12276404edcSAsim Jamshed }; 12376404edcSAsim Jamshed 12476404edcSAsim Jamshed 12576404edcSAsim Jamshed /** Initialize mOS context with parameters mentioned in the config file 12676404edcSAsim Jamshed * @param [in] config_file: location of config file 12776404edcSAsim Jamshed * @return 0 on success, -1 on error 12876404edcSAsim Jamshed * 12976404edcSAsim Jamshed * Setting dpdk devices, interface, load configuration from config file, 13076404edcSAsim Jamshed * routing table, arp table, etc. 13176404edcSAsim Jamshed */ 13276404edcSAsim Jamshed int 13376404edcSAsim Jamshed mtcp_init(const char *config_file); 13476404edcSAsim Jamshed 13576404edcSAsim Jamshed /** Destroy the global mOS context 13676404edcSAsim Jamshed * @return 0 on success, -1 on error 13776404edcSAsim Jamshed */ 13876404edcSAsim Jamshed int 13976404edcSAsim Jamshed mtcp_destroy(); 14076404edcSAsim Jamshed 14176404edcSAsim Jamshed /** Load current mtcp configuration in *conf 14276404edcSAsim Jamshed * @param [out] conf: configurations 14376404edcSAsim Jamshed * @return 0 on success, -1 on error 14476404edcSAsim Jamshed */ 14576404edcSAsim Jamshed int 14676404edcSAsim Jamshed mtcp_getconf(struct mtcp_conf *conf); 14776404edcSAsim Jamshed 14876404edcSAsim Jamshed /** Update mOS base with parameters mentioned in *conf 14976404edcSAsim Jamshed * @param [in] conf: configurations to set 15076404edcSAsim Jamshed * @return 0 on success, -1 on error 15176404edcSAsim Jamshed */ 15276404edcSAsim Jamshed int 15376404edcSAsim Jamshed mtcp_setconf(const struct mtcp_conf *conf); 15476404edcSAsim Jamshed 15576404edcSAsim Jamshed /** Bind a thread to a specific CPU core 15676404edcSAsim Jamshed * @param [in] cpu: CPU ID 15776404edcSAsim Jamshed * @return 0 on success, -1 on error 15876404edcSAsim Jamshed */ 15976404edcSAsim Jamshed int 16076404edcSAsim Jamshed mtcp_core_affinitize(int cpu); 16176404edcSAsim Jamshed 16276404edcSAsim Jamshed /** Create mOS/mtcp context thread based on the parameters passed 16376404edcSAsim Jamshed * by mtcp_init() & mtcp_setconf() functions 16476404edcSAsim Jamshed * @param [in] cpu: Core id to affinitize new mtcp thread 16576404edcSAsim Jamshed * @return mtcp context, NULL on error 16676404edcSAsim Jamshed */ 16776404edcSAsim Jamshed mctx_t 16876404edcSAsim Jamshed mtcp_create_context(int cpu); 16976404edcSAsim Jamshed 17076404edcSAsim Jamshed /** Destory mtcp context that was created by mOS/mTCP thread 17176404edcSAsim Jamshed * @param [in] mctx: mtcp context 17276404edcSAsim Jamshed * @return 0 on success, -1 on error 17376404edcSAsim Jamshed */ 17476404edcSAsim Jamshed int 17576404edcSAsim Jamshed mtcp_destroy_context(mctx_t mctx); 17676404edcSAsim Jamshed 17776404edcSAsim Jamshed /** Register signal handler (mtcp_sighandler_t handler ) 17876404edcSAsim Jamshed * for int signum 17976404edcSAsim Jamshed * @param [in] signum: Signal number to handle 18076404edcSAsim Jamshed * @param [in] handler: Handler function 18176404edcSAsim Jamshed * @return Same handler as input 18276404edcSAsim Jamshed */ 18376404edcSAsim Jamshed mtcp_sighandler_t 18476404edcSAsim Jamshed mtcp_register_signal(int signum, mtcp_sighandler_t handler); 18576404edcSAsim Jamshed 18676404edcSAsim Jamshed /** Create pipe 18776404edcSAsim Jamshed * @param [in] mctx: mtcp context 18876404edcSAsim Jamshed * @param [out] pipeid: created pipe 18976404edcSAsim Jamshed * @return 0 on success, -1 on error 19076404edcSAsim Jamshed */ 19176404edcSAsim Jamshed int 19276404edcSAsim Jamshed mtcp_pipe(mctx_t mctx, int pipeid[2]); 19376404edcSAsim Jamshed 19476404edcSAsim Jamshed /** Get socket options 19576404edcSAsim Jamshed * 19676404edcSAsim Jamshed * <ol> 19776404edcSAsim Jamshed * 198861ea7dfSAsim Jamshed * <li> Please see http://mos.kaist.edu/man/mtcp_getsockopt.html for 199861ea7dfSAsim Jamshed * the further informations. </li> 20076404edcSAsim Jamshed * 20176404edcSAsim Jamshed * <li> MOS_FRAGINFO_CLIBUF and MOS_FRAGINFO_SVRBUF \n 202861ea7dfSAsim Jamshed * Gives back offsets to fragments (non-contiguous data segments) currently 203861ea7dfSAsim Jamshed * stored in client’s TCP ring buffer. The optval is an array of 204861ea7dfSAsim Jamshed * `struct tcp_ring_fragment` 205861ea7dfSAsim Jamshed * where offset flow data starting from client’s TCP SYN sequence number, 206861ea7dfSAsim Jamshed * and len is the length of the tcp_ring_fragment. The optval holds the size 207861ea7dfSAsim Jamshed * of the array (in terms of the number of elements). </li> 20876404edcSAsim Jamshed * 209861ea7dfSAsim Jamshed * <li> MOS_INFO_CLIBUF and MOS_INFO_SVRBUF \n 210861ea7dfSAsim Jamshed * Returns meta-data regarding the client’s TCP ring buffer. This information 211861ea7dfSAsim Jamshed * is returned in the form of optval which is passed as struct tcp_buf_info. </li> 212861ea7dfSAsim Jamshed * 213861ea7dfSAsim Jamshed * <li> MOS_TCP_STATE_CLI and MOS_TCP_STATE_SVR \n 214861ea7dfSAsim Jamshed * Returns the current emulated state of the client. The optval argument is 215861ea7dfSAsim Jamshed * a pointer to an int whereas the optlen argument contains the sizeof(int). 216861ea7dfSAsim Jamshed * The optval returns a value of type enum tcpstate which can carry any one 217861ea7dfSAsim Jamshed * of the following states. </li> 21876404edcSAsim Jamshed * </ol> 21976404edcSAsim Jamshed * 22076404edcSAsim Jamshed * @param [in] mctx: mtcp context 22176404edcSAsim Jamshed * @param [in] sock: socket id 22276404edcSAsim Jamshed * @param [in] level: SOL_MONSOCKET 22376404edcSAsim Jamshed * @param [in] optname: __variable__ 22476404edcSAsim Jamshed * @param [out] optval: value of getting option 22576404edcSAsim Jamshed * @param [out] optlen: length of getting option 22676404edcSAsim Jamshed * @return Zero on success, -1 on error 22776404edcSAsim Jamshed */ 22876404edcSAsim Jamshed int 22976404edcSAsim Jamshed mtcp_getsockopt(mctx_t mctx, int sock, int level, 23076404edcSAsim Jamshed int optname, void *optval, socklen_t *optlen); 23176404edcSAsim Jamshed 23276404edcSAsim Jamshed /** Set socket options 23376404edcSAsim Jamshed * 23476404edcSAsim Jamshed * <ol> 23576404edcSAsim Jamshed * 23676404edcSAsim Jamshed * <li> MOS_CLIBUF and MOS_SVRBUF \n 237861ea7dfSAsim Jamshed * Dynamically adjust the size of the TCP receive ring buffer of the 238861ea7dfSAsim Jamshed * emulated client/server stack. The optval contains the size of the buffer 239861ea7dfSAsim Jamshed * that needs to be set as int, while optlen is equal to sizeof(int). </li> 24076404edcSAsim Jamshed * 241861ea7dfSAsim Jamshed * <li> MOS_CLIOVERLAP and MOS_SVROVERLAP \n 242861ea7dfSAsim Jamshed * Dynamically determine the policy on content overlap (e.g., overwriting 243861ea7dfSAsim Jamshed * with the retransmitted payload or not) for the client-side buffer. The 244861ea7dfSAsim Jamshed * optval can be either MOS_OVERLAP_POLICY_FIRST (to take the first data 245861ea7dfSAsim Jamshed * and never overwrite the buffer) or MOS_OVERLAP_POLICY_LAST (to always 246861ea7dfSAsim Jamshed * update the buffer with the last data), and optlen is equal to sizeof(int). </li> 24776404edcSAsim Jamshed * 24876404edcSAsim Jamshed * <li> MOS_STOP_MON \n 249861ea7dfSAsim Jamshed * Dynamically stop monitoring a flow for the specific side. This option can 250861ea7dfSAsim Jamshed * be used only with a MOS_SOCK_MONITOR_ACTIVE socket, which is given as a 251861ea7dfSAsim Jamshed * parameter in callback functions for every flow. The optval contains a side 252861ea7dfSAsim Jamshed * variable (MOS_SIDE_CLI, MOS_SIDE_SVR, or MOS_SIDE_BOTH), while optlen is 253861ea7dfSAsim Jamshed * equal to sizeof(int). </li> 254861ea7dfSAsim Jamshed * 25576404edcSAsim Jamshed * </ol> 25676404edcSAsim Jamshed * 25776404edcSAsim Jamshed * @param [in] mctx: mtcp context 25876404edcSAsim Jamshed * @param [in] sock: socket id 25976404edcSAsim Jamshed * @param [in] level: SOL_MONSOCKET 26076404edcSAsim Jamshed * @param [in] optname: __variable__ 26176404edcSAsim Jamshed * @param [in] optval: value of setting option 26276404edcSAsim Jamshed * @param [in] optlen: length of setting option 26376404edcSAsim Jamshed * @return Zero on success, -1 on error 26476404edcSAsim Jamshed */ 26576404edcSAsim Jamshed int 26676404edcSAsim Jamshed mtcp_setsockopt(mctx_t mctx, int sock, int level, 26776404edcSAsim Jamshed int optname, const void *optval, socklen_t optlen); 26876404edcSAsim Jamshed 26976404edcSAsim Jamshed /** Set socket as nonblock 27076404edcSAsim Jamshed * @param [in] mctx: mtcp context 27176404edcSAsim Jamshed * @param [in] sock: socket id 27276404edcSAsim Jamshed * @return Zero on success, -1 on error 27376404edcSAsim Jamshed * 27476404edcSAsim Jamshed * DEPRECATED 27576404edcSAsim Jamshed */ 27676404edcSAsim Jamshed int 27776404edcSAsim Jamshed mtcp_setsock_nonblock(mctx_t mctx, int sock); 27876404edcSAsim Jamshed 27976404edcSAsim Jamshed /** Control socket 28076404edcSAsim Jamshed * @param [in] mctx: mtcp context 28176404edcSAsim Jamshed * @param [in] sock: socket id 28276404edcSAsim Jamshed * @param [in] request: requested operation 28376404edcSAsim Jamshed * @param [in,out] argp: pointer to argument 28476404edcSAsim Jamshed * @return Zero on success, -1 on error 28576404edcSAsim Jamshed * 28676404edcSAsim Jamshed * Operations | Description 28776404edcSAsim Jamshed * ---------- | ----------- 28876404edcSAsim Jamshed * FIONREAD | number of data bytes in receive buffer 28976404edcSAsim Jamshed * FIONBIO | for non-blocking I/O 29076404edcSAsim Jamshed */ 29176404edcSAsim Jamshed int 29276404edcSAsim Jamshed mtcp_ioctl(mctx_t mctx, int sock, int request, void *argp); 29376404edcSAsim Jamshed 29476404edcSAsim Jamshed /** Create a socket 29576404edcSAsim Jamshed * @param [in] mctx: mtcp context 29676404edcSAsim Jamshed * @param [in] domain: AF_INET, Not used 29776404edcSAsim Jamshed * @param [in] type: Any of the following keyword 29876404edcSAsim Jamshed * - MOS_SOCK_STREAM (End TCP) 29976404edcSAsim Jamshed * - MOS_SOCK_MONITOR_RAW (Packet-level monitor) 30076404edcSAsim Jamshed * - MOS_SOCK_MONITOR_STREAM (Flow-level monitor) 30176404edcSAsim Jamshed * (MOS_SOCK_PROXY: To be supported) 30276404edcSAsim Jamshed * @param [in] protocol: NULL, Not used 30376404edcSAsim Jamshed * @return Zero on success, -1 on error 30476404edcSAsim Jamshed */ 30576404edcSAsim Jamshed int 30676404edcSAsim Jamshed mtcp_socket(mctx_t mctx, int domain, int type, int protocol); 30776404edcSAsim Jamshed 30876404edcSAsim Jamshed /** Bind a socket, same as `bind()` 30976404edcSAsim Jamshed * @return Zero on success, -1 on error 31076404edcSAsim Jamshed */ 31176404edcSAsim Jamshed int 31276404edcSAsim Jamshed mtcp_bind(mctx_t mctx, int sock, 31376404edcSAsim Jamshed const struct sockaddr *addr, socklen_t addrlen); 31476404edcSAsim Jamshed 31576404edcSAsim Jamshed /** Listen a listening socket, same as `listen()` 31676404edcSAsim Jamshed * @return Zero on success, -1 on error 31776404edcSAsim Jamshed * 31876404edcSAsim Jamshed * Only MOS_SOCK_LISTENER, MOS_SOCK_PROXY are allowed 31976404edcSAsim Jamshed */ 32076404edcSAsim Jamshed int 32176404edcSAsim Jamshed mtcp_listen(mctx_t mctx, int sock, int backlog); 32276404edcSAsim Jamshed 32376404edcSAsim Jamshed /** Accept new flow, same as `accept()` 32476404edcSAsim Jamshed * @param [in] mctx: mtcp context 32576404edcSAsim Jamshed * @param [in] sock: socket id for MOS_SOCK_STREAM 32676404edcSAsim Jamshed * @param [in] addr: address of the peer host(s) 32776404edcSAsim Jamshed * @param [in] addrlen: length of `addr` 32876404edcSAsim Jamshed * @return Zero on success, -1 on error 32976404edcSAsim Jamshed */ 33076404edcSAsim Jamshed int 33176404edcSAsim Jamshed mtcp_accept(mctx_t mctx, int sock, struct sockaddr *addr, socklen_t *addrlen); 33276404edcSAsim Jamshed 33376404edcSAsim Jamshed /** Initialize RSS pool for decide appropriate port numbers 33476404edcSAsim Jamshed * @param [in] mctx: mtcp context 33576404edcSAsim Jamshed * @param [in] saddr_base: source IP address base 33676404edcSAsim Jamshed * @param [in] num_addr: number of source IP address to use 33776404edcSAsim Jamshed * @param [in] daddr: destination IP address 33876404edcSAsim Jamshed * @param [in] dport: destination port number 33976404edcSAsim Jamshed * @return Zero on success, -1 on error 34076404edcSAsim Jamshed * 34176404edcSAsim Jamshed * w.r.t source IP addr, destination IP addr, destination port 34276404edcSAsim Jamshed */ 34376404edcSAsim Jamshed int 34476404edcSAsim Jamshed mtcp_init_rss(mctx_t mctx, in_addr_t saddr_base, int num_addr, 34576404edcSAsim Jamshed in_addr_t daddr, in_addr_t dport); 34676404edcSAsim Jamshed 34776404edcSAsim Jamshed /** Connect new flow, same as `connect()` 34876404edcSAsim Jamshed * @return Zero on success, -1 on error 34976404edcSAsim Jamshed */ 35076404edcSAsim Jamshed int 35176404edcSAsim Jamshed mtcp_connect(mctx_t mctx, int sock, 35276404edcSAsim Jamshed const struct sockaddr *addr, socklen_t addrlen); 35376404edcSAsim Jamshed 35476404edcSAsim Jamshed /** Close flow, same as `close()` 35576404edcSAsim Jamshed * @return Zero on success, -1 on error 35676404edcSAsim Jamshed */ 35776404edcSAsim Jamshed int 35876404edcSAsim Jamshed mtcp_close(mctx_t mctx, int sock); 35976404edcSAsim Jamshed 36076404edcSAsim Jamshed /** Abort flow by sending RST 36176404edcSAsim Jamshed * @return Zero on success, -1 on error 36276404edcSAsim Jamshed * 36376404edcSAsim Jamshed * Different from `mtcp_close()` which processes 4way handshake by FIN 36476404edcSAsim Jamshed */ 36576404edcSAsim Jamshed int 36676404edcSAsim Jamshed mtcp_abort(mctx_t mctx, int sock); 36776404edcSAsim Jamshed 368a5e1a556SAsim Jamshed /** Returns the current address to which the socket sockfd is bound 369a5e1a556SAsim Jamshed * @param [in] mctx: mtcp context 370a5e1a556SAsim Jamshed * @param [in] addr: address buffer to be filled 371a5e1a556SAsim Jamshed * @param [in] addrlen: amount of space pointed to by addr 372a5e1a556SAsim Jamshed * @return 0 on success, -1 on error 373a5e1a556SAsim Jamshed */ 374a5e1a556SAsim Jamshed int 375a5e1a556SAsim Jamshed mtcp_getsockname(mctx_t mctx, int sock, struct sockaddr *addr, socklen_t *addrlen); 376a5e1a556SAsim Jamshed 377df3fae06SAsim Jamshed /** Read byte stream from flow, same as `recv()` 378df3fae06SAsim Jamshed * For now, it can only accept flags 0 (default aka mtcp_read()) & MSG_PEEK 37976404edcSAsim Jamshed * @return number of bytes read on success, -1 on error 38076404edcSAsim Jamshed */ 38176404edcSAsim Jamshed ssize_t 382df3fae06SAsim Jamshed mtcp_recv(mctx_t mctx, int sockid, char *buf, size_t len, int flags); 383df3fae06SAsim Jamshed 384df3fae06SAsim Jamshed /** Read byte stream from flow, same as `read()` 385df3fae06SAsim Jamshed * @return number of bytes read on success, -1 on error 386df3fae06SAsim Jamshed */ 387*05e3289cSYoungGyoun ssize_t 38876404edcSAsim Jamshed mtcp_read(mctx_t mctx, int sock, char *buf, size_t len); 38976404edcSAsim Jamshed 39076404edcSAsim Jamshed /* readv should work in atomic */ 39176404edcSAsim Jamshed /** Read byte stream from flow in vector, same as `readv()` 39276404edcSAsim Jamshed * @return number of bytes read on success, -1 on error 39376404edcSAsim Jamshed */ 39476404edcSAsim Jamshed ssize_t 395a5e1a556SAsim Jamshed mtcp_readv(mctx_t mctx, int sock, const struct iovec *iov, int numIOV); 39676404edcSAsim Jamshed 39776404edcSAsim Jamshed /** Write byte stream to flow, same as `write()` 39876404edcSAsim Jamshed * @return number of bytes write on success, -1 on error 39976404edcSAsim Jamshed */ 40076404edcSAsim Jamshed ssize_t 401a5e1a556SAsim Jamshed mtcp_write(mctx_t mctx, int sock, const char *buf, size_t len); 40276404edcSAsim Jamshed 40376404edcSAsim Jamshed /* writev should work in atomic */ 40476404edcSAsim Jamshed /** Write byte stream to flow in vector, same as `writev()` 40576404edcSAsim Jamshed * @return number of bytes write on success, -1 on error 40676404edcSAsim Jamshed */ 40776404edcSAsim Jamshed ssize_t 408a5e1a556SAsim Jamshed mtcp_writev(mctx_t mctx, int sock, const struct iovec *iov, int numIOV); 40976404edcSAsim Jamshed 41076404edcSAsim Jamshed /** Get concurrent flow count of the underlying mtcp manager context (per-thread) 41176404edcSAsim Jamshed * @param [in] mctx: mtcp context 41276404edcSAsim Jamshed * @return concurrent flow count 41376404edcSAsim Jamshed */ 41476404edcSAsim Jamshed uint32_t 41576404edcSAsim Jamshed mtcp_get_connection_cnt(mctx_t mctx); 41676404edcSAsim Jamshed 41776404edcSAsim Jamshed #ifdef __cplusplus 41876404edcSAsim Jamshed }; 41976404edcSAsim Jamshed #endif 42076404edcSAsim Jamshed 42176404edcSAsim Jamshed #endif /* __MTCP_API_H_ */ 422