1 #ifndef ACL_VSTREAM_INCLUDE_H 2 #define ACL_VSTREAM_INCLUDE_H 10 #include <sys/types.h> 14 #include <sys/types.h> 18 #include <netinet/in.h> 25 #define ACL_VSTREAM_EOF (-1) 40 #define ACL_VSTREAM_BUFSIZE 4096 49 int count,
int timeout,
ACL_VSTREAM *fp,
void *context);
53 size_t size,
int timeout,
ACL_VSTREAM *fp,
void *context);
55 int count,
int timeout,
ACL_VSTREAM *fp,
void *context);
74 #define ACL_VSTREAM_TYPE_SOCK (1 << 0) 75 #define ACL_VSTREAM_TYPE_FILE (1 << 1) 76 #define ACL_VSTREAM_TYPE_LISTEN (1 << 2) 77 #define ACL_VSTREAM_TYPE_LISTEN_INET (1 << 3) 78 #define ACL_VSTREAM_TYPE_LISTEN_UNIX (1 << 4) 79 #define ACL_VSTREAM_TYPE_LISTEN_IOCP (1 << 5) 80 #define ACL_VSTREAM_TYPE_INET4 (1 << 6) 81 #define ACL_VSTREAM_TYPE_INET6 (1 << 7) 82 #define ACL_VSTREAM_TYPE_UNIX (1 << 8) 105 #define ACL_VSTREAM_FLAG_READ (1 << 0) 106 #define ACL_VSTREAM_FLAG_WRITE (1 << 1) 107 #define ACL_VSTREAM_FLAG_RW (1 << 2) 108 #define ACL_VSTREAM_FLAG_CACHE_SEEK (1 << 3) 109 #define ACL_VSTREAM_FLAG_DEFER_FREE (1 << 4) 111 #define ACL_VSTREAM_FLAG_ERR (1 << 10) 112 #define ACL_VSTREAM_FLAG_EOF (1 << 11) 113 #define ACL_VSTREAM_FLAG_TIMEOUT (1 << 12) 114 #define ACL_VSTREAM_FLAG_RDSHORT (1 << 13) 115 #define ACL_VSTREAM_FLAG_BAD (ACL_VSTREAM_FLAG_ERR \ 116 | ACL_VSTREAM_FLAG_EOF \ 117 | ACL_VSTREAM_FLAG_TIMEOUT) 118 #define ACL_VSTREAM_FLAG_CLIENT (1 << 14) 119 #define ACL_VSTREAM_FLAG_CONNECT (1 << 15) 120 #define ACL_VSTREAM_FLAG_SOCKPAIR (1 << 16) 122 #define ACL_VSTREAM_FLAG_TAGYES (1 << 17) 124 #define ACL_VSTREAM_FLAG_CONNECTING (1 << 18) 125 #define ACL_VSTREAM_FLAG_PREREAD (1 << 19) 127 #define ACL_VSTREAM_FLAG_MS (1 << 20) 128 #define ACL_VSTREAM_FLAG_US (1 << 21) 129 #define ACL_VSTREAM_FLAG_NS (1 << 22) 132 #define ACL_VSTREAM_SET_MS(x) ((x)->flag |= ACL_VSTREAM_FLAG_MS) 134 #define ACL_VSTREAM_SET_US(x) ((x)->flag |= ACL_VSTREAM_FLAG_US) 136 #define ACL_VSTREAM_SET_NS(x) ((x)->flag |= ACL_VSTREAM_FLAG_NS) 139 #define ACL_VSTREAM_CLR_MS(x) ((x)->flag &= ~ACL_VSTREAM_FLAG_MS) 141 #define ACL_VSTREAM_CLR_US(x) ((x)->flag &= ~ACL_VSTREAM_FLAG_US) 143 #define ACL_VSTREAM_CLR_NS(x) ((x)->flag &= ~ACL_VSTREAM_FLAG_NS) 146 #define ACL_VSTREAM_IS_MS(x) (((x)->flag & ACL_VSTREAM_FLAG_MS) != 0) 148 #define ACL_VSTREAM_IS_US(x) (((x)->flag & ACL_VSTREAM_FLAG_US) != 0) 150 #define ACL_VSTREAM_IS_NS(x) (((x)->flag & ACL_VSTREAM_FLAG_NS) != 0) 195 #if defined(_WIN32) || defined(_WIN64) 198 ACL_SOCKET iocp_sock;
199 #elif defined(ACL_UNIX) 206 #define ACL_VSTREAM_IN (&acl_vstream_fstd[0]) 207 #define ACL_VSTREAM_OUT (&acl_vstream_fstd[1]) 208 #define ACL_VSTREAM_ERR (&acl_vstream_fstd[2]) 268 size_t buflen,
int rw_timeo,
int fdtype);
282 int mode,
size_t buflen);
309 #define ACL_VSTREAM_CTL_END 0 310 #define ACL_VSTREAM_CTL_READ_FN 1 311 #define ACL_VSTREAM_CTL_WRITE_FN 2 312 #define ACL_VSTREAM_CTL_PATH 3 313 #define ACL_VSTREAM_CTL_FD 4 314 #define ACL_VSTREAM_CTL_TIMEOUT 5 315 #define ACL_VSTREAM_CTL_CONTEXT 6 316 #define ACL_VSTREAM_CTL_CTX ACL_VSTREAM_CTL_CONTEXT 317 #define ACL_VSTREAM_CTL_CACHE_SEEK 7 386 #define acl_vstream_get_char acl_vstream_getc 440 #define acl_vstream_readline acl_vstream_gets 441 #define acl_vstream_fgets acl_vstream_gets 466 const char *tag,
size_t taglen);
612 #define acl_vstream_buffed_fwrite acl_vstream_buffed_writen 704 const
char *
fmt, ...);
737 #define acl_vstream_fwrite acl_vstream_writen 750 #define acl_vstream_fclose acl_vstream_close 765 void (*close_fn)(
ACL_VSTREAM*,
void*),
void *context);
774 void (*close_fn)(
ACL_VSTREAM*,
void*),
void *context);
801 #define ACL_VSTREAM_GETC(stream_ptr) ( \ 802 (stream_ptr)->read_cnt > 0 ? \ 803 (stream_ptr)->read_cnt--, \ 804 (stream_ptr)->offset++, \ 805 *(stream_ptr)->read_ptr++: \ 806 (stream_ptr)->sys_getc((stream_ptr))) 813 #define ACL_VSTREAM_PUTC(ch, stream_ptr) ( \ 814 (stream_ptr)->wbuf_size == 0 ? \ 815 (acl_vstream_buffed_space((stream_ptr)), \ 816 ((stream_ptr)->wbuf[(size_t) (stream_ptr)->wbuf_dlen++] = (ch))) \ 817 : ((stream_ptr)->wbuf_dlen == stream_ptr->wbuf_size ? \ 818 (acl_vstream_fflush((stream_ptr)) == ACL_VSTREAM_EOF ? \ 820 : ((stream_ptr)->wbuf[(size_t) (stream_ptr)->wbuf_dlen++] = (ch))) \ 821 : ((stream_ptr)->wbuf[(size_t) (stream_ptr)->wbuf_dlen++] = (ch)))) 827 #define ACL_VSTREAM_SOCK(stream_ptr) ((stream_ptr)->fd.sock) 833 #define ACL_VSTREAM_FILE(stream_ptr) ((stream_ptr)->fd.h_file) 839 #define ACL_VSTREAM_PATH(stream_ptr) ((stream_ptr)->path) 851 #define ACL_VSTREAM_PEER(stream_ptr) ((stream_ptr)->addr_peer) 871 #define ACL_VSTREAM_LOCAL(stream_ptr) ((stream_ptr)->addr_local) 902 #define ACL_VSTREAM_SET_SOCK(stream_ptr, _fd) do { \ 903 ACL_VSTREAM *__stream_ptr = stream_ptr; \ 904 __stream_ptr->fd.sock = _fd; \ 912 #define ACL_VSTREAM_SET_FILE(stream_ptr, _fh) do { \ 913 ACL_VSTREAM *__stream_ptr = stream_ptr; \ 914 __stream_ptr->fd.h_file = _fh; \ 924 #define ACL_VSTREAM_BFRD_CNT(stream_ptr) \ 925 ((stream_ptr) == NULL ? -1 : (stream_ptr)->read_cnt) 932 #define ACL_VSTREAM_SET_RWTIMO(stream_ptr, _rw_timeo) do { \ 933 ACL_VSTREAM *__stream_ptr = stream_ptr; \ 934 __stream_ptr->rw_timeout = _rw_timeo; \ 941 #define ACL_VSTREAM_SET_EOF(stream_ptr) do { \ 942 ACL_VSTREAM *__stream_ptr = stream_ptr; \ 943 __stream_ptr->flag |= ACL_VSTREAM_FLAG_EOF; \ 951 #define ACL_IF_VSTREAM_ERR(stream_ptr) \ 952 ((stream_ptr)->flag & ACL_VSTREAM_FLAG_BAD) 963 #define ACL_VSTREAM_ERRNO(stream_ptr) ((stream_ptr)->errnum) 970 #define acl_vstream_ftimeout(stream_ptr) \ 971 ((stream_ptr)->flag & ACL_VSTREAM_FLAG_TIMEOUT)
ACL_API int acl_vstream_set_local_addr(ACL_VSTREAM *fp, const struct sockaddr *sa)
ACL_FSTREAM_RD_FN fread_fn
ACL_API int const char ACL_API int acl_vstream_buffed_printf(const char *,...)
ACL_API int acl_vstream_readn(ACL_VSTREAM *fp, void *vptr, size_t maxlen)
ACL_API int acl_vstream_buffed_puts(const char *s)
ACL_API int acl_vstream_buffed_vfprintf(ACL_VSTREAM *fp, const char *fmt, va_list ap)
ACL_API int const char ACL_API int acl_vstream_printf(const char *,...)
ACL_API int acl_vstream_puts(const char *s)
ACL_API int acl_vstream_vfprintf(ACL_VSTREAM *fp, const char *fmt, va_list ap)
ACL_API void acl_vstream_ctl(ACL_VSTREAM *fp, int name,...)
HTTP_API void const char * name
ACL_API ACL_VSTREAM acl_vstream_fstd[]
ACL_API int acl_file_truncate(const char *path, acl_off_t length)
ACL_API void * acl_vstream_get_object(ACL_VSTREAM *fp, const char *key)
ACL_API ACL_VSTREAM * acl_vstream_fdopen(ACL_SOCKET fd, unsigned int oflags, size_t buflen, int rw_timeo, int fdtype)
ACL_API int acl_vstream_write(ACL_VSTREAM *fp, const void *vptr, int dlen)
struct ACL_VSTREAM_CLOSE_HANDLE ACL_VSTREAM_CLOSE_HANDLE
ACL_API ACL_VSTREAM * acl_vstream_fopen(const char *path, unsigned int oflags, int mode, size_t buflen)
ACL_ARRAY * close_handle_lnk
ACL_API int acl_vstream_buffed_writen(ACL_VSTREAM *fp, const void *vptr, size_t dlen)
int(* close_fn)(ACL_SOCKET)
int(* ACL_VSTREAM_WR_FN)(ACL_SOCKET fd, const void *buf, size_t size, int timeout, ACL_VSTREAM *fp, void *context)
ACL_API int acl_vstream_fsync(ACL_VSTREAM *fp)
int(* ACL_FSTREAM_WV_FN)(ACL_FILE_HANDLE fh, const struct iovec *vec, int count, int timeout, ACL_VSTREAM *fp, void *context)
ACL_VSTREAM_WR_FN write_fn
int(* ACL_FSTREAM_WR_FN)(ACL_FILE_HANDLE fh, const void *buf, size_t size, int timeout, ACL_VSTREAM *fp, void *context)
ACL_API int acl_vstream_fstat(ACL_VSTREAM *fp, struct acl_stat *buf)
ACL_API void acl_vstream_set_local(ACL_VSTREAM *fp, const char *addr)
ACL_API void acl_socket_close_hook(int(*close_fn)(ACL_SOCKET))
ACL_API int ACL_PRINTF(2, 3) acl_vstream_buffed_fprintf(ACL_VSTREAM *fp
ACL_API acl_off_t acl_vstream_ftell(ACL_VSTREAM *fp)
ACL_API void acl_vstream_clean_close_handle(ACL_VSTREAM *fp)
int(* sys_getc)(ACL_VSTREAM *)
ACL_API int acl_vstream_writev(ACL_VSTREAM *fp, const struct iovec *vector, int count)
ACL_API void acl_vstream_delete_close_handle(ACL_VSTREAM *fp, void(*close_fn)(ACL_VSTREAM *, void *), void *context)
ACL_API void acl_vstream_call_close_handles(ACL_VSTREAM *fp)
struct sockaddr * sa_local
ACL_API void acl_vstream_init(void)
int(* ACL_VSTREAM_RD_FN)(ACL_SOCKET fd, void *buf, size_t size, int timeout, ACL_VSTREAM *fp, void *context)
ACL_API int acl_vstream_gets_nonl(ACL_VSTREAM *fp, void *vptr, size_t maxlen)
ACL_API int acl_vstream_writen(ACL_VSTREAM *fp, const void *vptr, size_t dlen)
int(* fclose_fn)(ACL_FILE_HANDLE)
ACL_API int acl_vstream_can_read(ACL_VSTREAM *fp)
ACL_API void acl_vstream_free(ACL_VSTREAM *fp)
ACL_API void acl_socket_write_hook(ACL_VSTREAM_WR_FN write_fn)
ACL_API void acl_socket_writev_hook(ACL_VSTREAM_WV_FN writev_fn)
ACL_API int acl_vstream_close(ACL_VSTREAM *fp)
ACL_API int acl_vstream_bfcp_some(ACL_VSTREAM *fp, void *vptr, size_t maxlen)
ACL_API int acl_vstream_read(ACL_VSTREAM *fp, void *vptr, size_t maxlen)
ACL_API int acl_vstream_getc(ACL_VSTREAM *fp)
ACL_API int acl_vstream_gets(ACL_VSTREAM *fp, void *vptr, size_t maxlen)
ACL_VSTREAM_RD_FN read_fn
int(* ACL_VSTREAM_WV_FN)(ACL_SOCKET fd, const struct iovec *vec, int count, int timeout, ACL_VSTREAM *fp, void *context)
ACL_API int acl_vstream_ungetc(ACL_VSTREAM *fp, int ch)
ACL_API int acl_vstream_add_object(ACL_VSTREAM *fp, const char *key, void *obj)
int(* ACL_FSTREAM_RD_FN)(ACL_FILE_HANDLE fh, void *buf, size_t size, int timeout, ACL_VSTREAM *fp, void *context)
ACL_API ACL_VSTREAM * acl_vstream_fhopen(ACL_FILE_HANDLE fh, unsigned int oflags)
ACL_API void acl_vstream_buffed_space(ACL_VSTREAM *fp)
ACL_API int acl_vstream_peekfd(ACL_VSTREAM *fp)
ACL_API acl_off_t acl_vstream_fseek2(ACL_VSTREAM *fp, acl_off_t offset, int whence)
ACL_API char * acl_vstream_loadfile2(const char *path, ssize_t *size)
ACL_FSTREAM_WV_FN fwritev_fn
ACL_API int acl_vstream_set_peer_addr(ACL_VSTREAM *fp, const struct sockaddr *sa)
ACL_API void acl_vstream_set_peer(ACL_VSTREAM *fp, const char *addr)
ACL_API void acl_vstream_set_path(ACL_VSTREAM *fp, const char *path)
ACL_API int acl_vstream_fflush(ACL_VSTREAM *fp)
acl_off_t total_write_cnt
ACL_API int acl_vstream_nonb_readn(ACL_VSTREAM *fp, char *buf, int size)
ACL_FSTREAM_WR_FN fwrite_fn
ACL_API int acl_vstream_del_object(ACL_VSTREAM *fp, const char *key)
ACL_API int acl_vstream_probe_status(ACL_VSTREAM *fp)
ACL_API int acl_vstream_gets_nonl_peek(ACL_VSTREAM *fp, ACL_VSTRING *buf, int *ready)
ACL_API acl_int64 acl_vstream_fsize(ACL_VSTREAM *fp)
ACL_API int acl_file_ftruncate(ACL_VSTREAM *fp, acl_off_t length)
ACL_API int acl_vstream_read_peek3(ACL_VSTREAM *fp, void *buf, size_t size)
ACL_API acl_off_t acl_vstream_fseek(ACL_VSTREAM *fp, acl_off_t offset, int whence)
ACL_API void acl_vstream_reset(ACL_VSTREAM *fp)
ACL_API int acl_vstream_fputs(const char *s, ACL_VSTREAM *fp)
ACL_API const char * acl_vstream_strerror(ACL_VSTREAM *fp)
struct sockaddr * sa_peer
ACL_API void acl_vstream_add_close_handle(ACL_VSTREAM *fp, void(*close_fn)(ACL_VSTREAM *, void *), void *context)
ACL_API char * acl_vstream_loadfile(const char *path)
ACL_API int acl_vstream_buffed_fputs(const char *s, ACL_VSTREAM *fp)
ACL_API int acl_vstream_readtags(ACL_VSTREAM *fp, void *vptr, size_t maxlen, const char *tag, size_t taglen)
ACL_API int const char * fmt
void(* close_fn)(ACL_VSTREAM *, void *)
ACL_API void acl_socket_read_hook(ACL_VSTREAM_RD_FN read_fn)
ACL_API int acl_vstream_gets_peek(ACL_VSTREAM *fp, ACL_VSTRING *buf, int *ready)
ACL_API int acl_vstream_writevn(ACL_VSTREAM *fp, const struct iovec *vector, int count)
ACL_API int acl_vstream_readn_peek(ACL_VSTREAM *fp, ACL_VSTRING *buf, int cnt, int *ready)
ACL_API int acl_vstream_set_fdtype(ACL_VSTREAM *fp, int type)
ACL_API ACL_VSTREAM * acl_vstream_clone(const ACL_VSTREAM *stream_src)
ACL_VSTREAM_WV_FN writev_fn
ACL_API int acl_vstream_unread(ACL_VSTREAM *fp, const void *ptr, size_t length)
ACL_API int acl_vstream_read_peek(ACL_VSTREAM *fp, ACL_VSTRING *buf)