全て データ構造 ファイル 関数 変数 型定義 列挙型 列挙型の値 マクロ定義
include/c/urg_tcpclient.h
説明を見る。
00001 #ifndef URG_TCPCLIENT_H
00002 #define URG_TCPCLIENT_H
00003 
00013 #ifdef __cplusplus
00014 extern "C" {
00015 #endif
00016 
00017 #include "urg_ring_buffer.h"
00018 #include "urg_detect_os.h"
00019 #include <sys/types.h>
00020 #if defined(URG_WINDOWS_OS)
00021 #include <windows.h>
00022 #else
00023 #include <sys/socket.h>
00024 #include <netinet/in.h>
00025 #include <arpa/inet.h>
00026 #endif
00027 
00028 
00029 // -- NOT INTERFACE, for internal use only --
00030 // For urg_ringbuffer.h
00031 // The size of buffer must be specified by the power of 2
00032 // i.e. ring buffer size = two to the RB_BITSHIFT-th power.
00033 enum {
00034     RB_BITSHIFT = 8,
00035     RB_SIZE = 1 << RB_BITSHIFT,
00036 
00037     // caution ! available buffer size is less than the
00038     // size given to the ring buffer(RB_SIZE).
00039     BUFSIZE = RB_SIZE - 1,
00040 };
00041 
00042 
00044 typedef struct {
00045     // socket
00046     struct sockaddr_in server_addr;
00047     int sock_desc;
00048     int sock_addr_size;
00049 
00050     // buffer
00051     ring_buffer_t rb;
00052     char buf[RB_SIZE];
00053 
00054     // line reading functions
00055     int pushed_back; // for pushded back char
00056 
00057 } urg_tcpclient_t;
00058 // -- end of NON INTERFACE definitions --
00059 
00060 
00061 // -- belows are MODULE INTERFACES --
00072 extern int tcpclient_open(urg_tcpclient_t* cli,
00073                           const char* server_ip_str, int port_num);
00074 
00075 
00081 extern void tcpclient_close(urg_tcpclient_t* cli);
00082 
00083 
00094 extern int tcpclient_read(urg_tcpclient_t* cli,
00095                           char* userbuf, int req_size, int timeout);
00096 
00097 
00107 extern int tcpclient_write(urg_tcpclient_t* cli,
00108                            const char* userbuf, int req_size);
00109 
00110 
00112 extern int tcpclient_error(urg_tcpclient_t* cli,
00113                            char* error_message, int max_size);
00114 
00115 
00126 extern int tcpclient_readline(urg_tcpclient_t* cli,
00127                               char* userbuf, int buf_size, int timeout);
00128 
00129 #ifdef __cplusplus
00130 }
00131 #endif
00132 
00133 #endif /* !URG_TCPCLIENT_H */