Go to the documentation of this file.00001 #ifndef URG_TCPCLIENT_H
00002 #define URG_TCPCLIENT_H
00003
00013 #ifdef __cplusplus
00014 extern "C" {
00015 #endif
00016
00017 #include "urg_c/urg_ring_buffer.h"
00018 #include "urg_c/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
00030
00031
00032
00033 enum {
00034 RB_BITSHIFT = 8,
00035 RB_SIZE = 1 << RB_BITSHIFT,
00036
00037
00038
00039 BUFSIZE = RB_SIZE - 1,
00040 };
00041
00042
00044 typedef struct {
00045
00046 struct sockaddr_in server_addr;
00047 int sock_desc;
00048 int sock_addr_size;
00049
00050
00051 ring_buffer_t rb;
00052 char buf[RB_SIZE];
00053
00054
00055 int pushed_back;
00056
00057 } urg_tcpclient_t;
00058
00059
00060
00061
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