ytcp.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * $Id: ytcp.h 28224 2017-07-31 14:53:54Z seb $
4  *
5  * Declaration of a client TCP stack
6  *
7  * - - - - - - - - - License information: - - - - - - - - -
8  *
9  * Copyright (C) 2011 and beyond by Yoctopuce Sarl, Switzerland.
10  *
11  * Yoctopuce Sarl (hereafter Licensor) grants to you a perpetual
12  * non-exclusive license to use, modify, copy and integrate this
13  * file into your software for the sole purpose of interfacing
14  * with Yoctopuce products.
15  *
16  * You may reproduce and distribute copies of this file in
17  * source or object form, as long as the sole purpose of this
18  * code is to interface with Yoctopuce products. You must retain
19  * this notice in the distributed source file.
20  *
21  * You should refer to Yoctopuce General Terms and Conditions
22  * for additional information regarding your rights and
23  * obligations.
24  *
25  * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
26  * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
27  * WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS
28  * FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO
29  * EVENT SHALL LICENSOR BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
30  * INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
31  * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR
32  * SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT
33  * LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR
34  * CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON THE
35  * BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF
36  * WARRANTY, OR OTHERWISE.
37  *
38  *********************************************************************/
39 
40 
41 #ifndef YTCP_H
42 #define YTCP_H
43 
44 
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 #include "ydef.h"
51 
52 
53 #ifdef WINDOWS_API
54 /**************************************************************
55  *
56  * WINDOWS IMPLEMENTATION
57  *
58  **************************************************************/
59 
60 //SOCKET RELATED DEFIITIONS AND INCLUDE
61 #else
62 #define SOCKET_ERROR -1
63 #define INVALID_SOCKET -1
64 #define closesocket(s) close(s)
65 #include <sys/socket.h>
66 #include <netinet/in.h>
67 #include <arpa/inet.h>
68 #include <netinet/tcp.h>
69 #endif
70 
71 #ifdef MSG_NOSIGNAL
72 #define SEND_NOSIGPIPE MSG_NOSIGNAL
73 #else
74 #define SEND_NOSIGPIPE 0
75 #endif
76 
77 #ifdef WINDOWS_API
78 #define SOCK_ERR (WSAGetLastError())
79 #else
80 #define SOCK_ERR (errno)
81 #endif
82 #define REPORT_ERR(msg) if(errmsg){ YSPRINTF(errmsg,YOCTO_ERRMSG_LEN,"%s (%s:%d / errno=%d)",(msg), __FILE_ID__, __LINE__, SOCK_ERR);errmsg[YOCTO_ERRMSG_LEN-1]='\0';}
83 
84 #define yNetSetErr() yNetSetErrEx(__LINE__,SOCK_ERR,errmsg)
85 
86 int yNetSetErrEx(u32 line,unsigned err,char *errmsg);
87 
88 #define YTCP_REMOTE_CLOSE 1
89 
90 struct _HubSt;
91 struct _RequestSt;
92 
93 typedef struct {
96 } WakeUpSocket;
97 
98 void yDupSet(char **storage, const char *val);
100 int yStartWakeUpSocket(WakeUpSocket *wuce, char *errmsg);
101 int yDringWakeUpSocket(WakeUpSocket *wuce, u8 signal, char *errmsg);
102 int yConsumeWakeUpSocket(WakeUpSocket *wuce, char *errmsg);
103 void yFreeWakeUpSocket(WakeUpSocket *wuce);
104 int yTcpDownload(const char *host, const char *url, u8 **out_buffer, u32 mstimeout, char *errmsg);
105 
106 int yTcpInit(char *errmsg);
107 void yTcpShutdown(void);
108 u32 yResolveDNS(const char *name,char *errmsg);
109 
110 
111 
112 struct _RequestSt * yReqAlloc( struct _HubSt *hub);
113 int yReqOpen(struct _RequestSt *tcpreq, int wait_for_start, int tcpchan, const char *request, int reqlen, u64 mstimeout, yapiRequestAsyncCallback callback, void *context, yapiRequestProgressCallback progress_cb, void *progress_ctx, char *errmsg);
114 int yReqIsAsync(struct _RequestSt *req);
115 int yReqSelect(struct _RequestSt *tcpreq, u64 ms, char *errmsg);
116 int yReqMultiSelect(struct _RequestSt **tcpreq, int size, u64 ms, WakeUpSocket *wuce, char *errmsg);
117 int yReqIsEof(struct _RequestSt *tcpreq, char *errmsg);
118 int yReqGet(struct _RequestSt *tcpreq, u8 **buffer);
119 int yReqRead(struct _RequestSt *rcoreq, u8 *buffer, int len);
120 void yReqClose(struct _RequestSt *tcpreq);
121 void yReqFree(struct _RequestSt *tcpreq);
122 int yReqHasPending(struct _HubSt *hub);
123 
124 
125 void* ws_thread(void* ctx);
126 
127 
128 #include "ythread.h"
129 
130 #define OS_IFACE_CAN_MCAST 1
131 
132 typedef struct {
133  u32 flags;
134  u32 ip;
135  u32 netmask;
136 } os_ifaces;
137 
138 #ifdef YAPI_IN_YDEVICE
139 extern os_ifaces detectedIfaces[];
140 extern int nbDetectedIfaces;
141 int yDetectNetworkInterfaces(u32 only_ip);
142 
143 #endif
144 
145 #define SSDP_UUID_LEN 48
146 #define SSDP_URL_LEN 48
147 
148 typedef struct
149 {
150  char serial[YOCTO_SERIAL_LEN];
151  char uuid[SSDP_UUID_LEN];
152  char url[SSDP_URL_LEN];
154  u64 maxAge;
156 
157 
158 // prototype of the ssdp hub discovery callback
159 // will be called on discover, refresh, and expiration
160 typedef void (*ssdpHubDiscoveryCallback)(const char *serial, const char *urlToRegister, const char *urlToUnregister);
161 
162 #define NB_SSDP_CACHE_ENTRY 32
163 #define NB_OS_IFACES 8
164 
165 
166 typedef struct {
167  int started;
169  YSOCKET request_sock[NB_OS_IFACES];
170  YSOCKET notify_sock[NB_OS_IFACES];
173 } SSDPInfos;
174 
176 int ySSDPDiscover(SSDPInfos *SSDP, char *errmsg);
177 void ySSDPStop(SSDPInfos *SSDP);
178 
179 #ifdef __cplusplus
180 }
181 #endif
182 #endif
int yStartWakeUpSocket(WakeUpSocket *wuce, char *errmsg)
Definition: ytcp.c:225
int nbDetectedIfaces
Definition: ytcp.c:2814
int ySSDPStart(SSDPInfos *SSDP, ssdpHubDiscoveryCallback callback, char *errmsg)
Definition: ytcp.c:3253
void yReqClose(struct _RequestSt *tcpreq)
Definition: ytcp.c:1561
u64 maxAge
Definition: ytcp.h:154
#define SSDP_UUID_LEN
Definition: ytcp.h:145
int yNetSetErrEx(u32 line, unsigned err, char *errmsg)
Definition: ytcp.c:141
ssdpHubDiscoveryCallback callback
Definition: ytcp.h:168
int yReqGet(struct _RequestSt *tcpreq, u8 **buffer)
Definition: ytcp.c:1504
void ySSDPStop(SSDPInfos *SSDP)
Definition: ytcp.c:3330
void yDupSet(char **storage, const char *val)
Definition: ytcp.c:128
void(* yapiRequestProgressCallback)(void *context, u32 acked, u32 totalbytes)
Definition: ydef.h:866
int yConsumeWakeUpSocket(WakeUpSocket *wuce, char *errmsg)
Definition: ytcp.c:271
Definition: ytcp.h:148
#define SSDP_URL_LEN
Definition: ytcp.h:146
#define YOCTO_SERIAL_LEN
Definition: ydef.h:420
char errmsg[YOCTO_ERRMSG_LEN]
Definition: yproto.h:874
int yDringWakeUpSocket(WakeUpSocket *wuce, u8 signal, char *errmsg)
Definition: ytcp.c:263
u32 ip
Definition: ytcp.h:134
Definition: yproto.h:798
void yReqFree(struct _RequestSt *tcpreq)
Definition: ytcp.c:1606
int yReqMultiSelect(struct _RequestSt **tcpreq, int size, u64 ms, WakeUpSocket *wuce, char *errmsg)
Definition: ytcp.c:1479
os_ifaces detectedIfaces[NB_OS_IFACES]
Definition: ytcp.c:2813
YSOCKET listensock
Definition: ytcp.h:94
HubSt * hub
Definition: yproto.h:859
u32 netmask
Definition: ytcp.h:135
#define NB_OS_IFACES
Definition: ytcp.h:163
void yFreeWakeUpSocket(WakeUpSocket *wuce)
Definition: ytcp.c:281
int yReqOpen(struct _RequestSt *tcpreq, int wait_for_start, int tcpchan, const char *request, int reqlen, u64 mstimeout, yapiRequestAsyncCallback callback, void *context, yapiRequestProgressCallback progress_cb, void *progress_ctx, char *errmsg)
Definition: ytcp.c:1362
void * ws_thread(void *ctx)
Definition: ytcp.c:2537
YSTATIC int yDetectNetworkInterfaces(u32 only_ip)
Definition: ytcp.c:2858
int YSOCKET
Definition: ydef.h:236
u32 yResolveDNS(const char *name, char *errmsg)
Definition: ytcp.c:296
void * context
Definition: yproto.h:883
int yReqHasPending(struct _HubSt *hub)
Definition: ytcp.c:1629
YSOCKET signalsock
Definition: ytcp.h:95
void(* ssdpHubDiscoveryCallback)(const char *serial, const char *urlToRegister, const char *urlToUnregister)
Definition: ytcp.h:160
int yReqIsEof(struct _RequestSt *tcpreq, char *errmsg)
Definition: ytcp.c:1486
void(* yapiRequestAsyncCallback)(void *context, const u8 *result, u32 resultlen, int retcode, const char *errmsg)
Definition: ydef.h:864
int yReqRead(struct _RequestSt *rcoreq, u8 *buffer, int len)
Definition: ytcp.c:1525
void yInitWakeUpSocket(WakeUpSocket *wuce)
Definition: ytcp.c:218
struct _RequestSt * yReqAlloc(struct _HubSt *hub)
Definition: ytcp.c:1337
yThread thread
Definition: ytcp.h:171
yapiRequestAsyncCallback callback
Definition: yproto.h:882
int started
Definition: ytcp.h:167
u64 detectedTime
Definition: ytcp.h:153
void yTcpShutdown(void)
Definition: ytcp.c:382
#define NB_SSDP_CACHE_ENTRY
Definition: ytcp.h:162
u32 flags
Definition: ytcp.h:133
int yTcpInit(char *errmsg)
Definition: ytcp.c:364
int yTcpDownload(const char *host, const char *url, u8 **out_buffer, u32 mstimeout, char *errmsg)
Definition: ytcp.c:702
int yReqIsAsync(struct _RequestSt *req)
Definition: ytcp.c:1596
int yReqSelect(struct _RequestSt *tcpreq, u64 ms, char *errmsg)
Definition: ytcp.c:1470
int ySSDPDiscover(SSDPInfos *SSDP, char *errmsg)
Definition: ytcp.c:3233


yoctopuce_altimeter
Author(s): Anja Sheppard
autogenerated on Mon Jun 10 2019 15:49:13