libuv/ol.h
2011-03-23 05:57:17 -07:00

110 lines
2.2 KiB
C

#ifdef windows
# include "ol_win.h"
#else
# include "ol_unix.h"
#endif
typedef ol_read_cb void(*)(ol_buf *bufs, int bufcnt);
typedef ol_close_cb void(*)(int read, int write);
typedef ol_connect_cb void(*)();
/**
* Do not make assumptions about the order of the elements in this sturct.
* Always use offsetof because the order is platform dependent. Has a char*
* buf and size_t len. That's all you need to know.
*/
struct ol_buf;
/**
* Creates a tcp h. If bind_addr is NULL a random
* port will be bound.
*/
ol_handle* ol_tcp_new(int v4, ol_read_cb read_cb, ol_close_cb close_cb);
ol_handle* ol_file_new(char *filename, int read, ol_read_cb cb,
ol_close_cb cb);
/**
* In the case of servers, give a filename. In the case of clients
* leave filename NULL.
*/
ol_handle* ol_named_pipe_new(char *filename, ol_read_cb cb,
ol_close_cb cb);
ol_handle* ol_tty_new(ol_tty_read_cb cb, ol_close_cb cb);
/**
* Only works with named pipes and TCP sockets.
*/
int ol_connect(ol_handle* h, sockaddr* addr, sockaddr_len len,
ol_buf* buf, size_t* bytes_sent, ol_connect_cb ol);
/**
* Depth of write buffer in bytes.
*/
size_t ol_buffer_size(ol_handle* h);
int ol_pause(ol_handle* h);
int ol_resume(ol_handle* h);
/**
* Returns file descriptor associated with the handle. There may be only
* limited numbers of file descriptors allowed by the operating system. On
* Windows this limit is 2048 (see
* _setmaxstdio[http://msdn.microsoft.com/en-us/library/6e3b887c.aspx])
*/
int ol_get_fd(ol_handle* h);
/**
* Send data to h. User responsible for bufs until callback is made.
* Multiple ol_handle_write() calls may be issued before the previous ones
* complete - data will sent in the correct order.
*/
int ol_write(ol_handle* h, ol_buf* bufs, int bufcnt,
size_t* bytes_sent, ol_write_cb cb);
/**
* Note: works on both named pipes and TCP handles.
*/
int ol_listen(ol_handle* h, int backlog, ol_accept_cb cb);
/**
* Writes EOF or sends a FIN packet.
*/
int ol_end(ol_handle* h);
int ol_close(ol_handle* h);
/**
* Releases memory associated with handle. You MUST call this after
* ol_close_cb() is made with both 0 arguments.
*/
int ol_free(ol_handle* h);
ol_loop* ol_loop_new();
ol_loop* ol_associate(ol_handle* handle);
void ol_run();