Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00081 #ifndef __PSOCK_H__
00082 #define __PSOCK_H__
00083
00084 #include "uipopt.h"
00085 #include "pt.h"
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 struct psock_buf {
00096 u8_t *ptr;
00097 unsigned short left;
00098 };
00099
00106 struct psock {
00107 struct pt pt, psockpt;
00108
00109
00110 const u8_t *sendptr;
00111 u8_t *readptr;
00112
00113 char *bufptr;
00114
00115
00116 u16_t sendlen;
00117 u16_t readlen;
00118
00119 struct psock_buf buf;
00120
00121 unsigned int bufsize;
00122
00123 unsigned char state;
00124 };
00125
00126 void psock_init(struct psock *psock, char *buffer, unsigned int buffersize);
00144 #define PSOCK_INIT(psock, buffer, buffersize) \
00145 psock_init(psock, buffer, buffersize)
00146
00158 #define PSOCK_BEGIN(psock) PT_BEGIN(&((psock)->pt))
00159
00160 PT_THREAD(psock_send(struct psock *psock, const char *buf, unsigned int len));
00178 #define PSOCK_SEND(psock, data, datalen) \
00179 PT_WAIT_THREAD(&((psock)->pt), psock_send(psock, data, datalen))
00180
00191 #define PSOCK_SEND_STR(psock, str) \
00192 PT_WAIT_THREAD(&((psock)->pt), psock_send(psock, str, strlen(str)))
00193
00194 PT_THREAD(psock_generator_send(struct psock *psock,
00195 unsigned short (*f)(void *), void *arg));
00196
00219 #define PSOCK_GENERATOR_SEND(psock, generator, arg) \
00220 PT_WAIT_THREAD(&((psock)->pt), \
00221 psock_generator_send(psock, generator, arg))
00222
00223
00235 #define PSOCK_CLOSE(psock) uip_close()
00236
00237 PT_THREAD(psock_readbuf(struct psock *psock));
00250 #define PSOCK_READBUF(psock) \
00251 PT_WAIT_THREAD(&((psock)->pt), psock_readbuf(psock))
00252
00253 PT_THREAD(psock_readto(struct psock *psock, unsigned char c));
00268 #define PSOCK_READTO(psock, c) \
00269 PT_WAIT_THREAD(&((psock)->pt), psock_readto(psock, c))
00270
00281 #define PSOCK_DATALEN(psock) psock_datalen(psock)
00282
00283 u16_t psock_datalen(struct psock *psock);
00284
00297 #define PSOCK_EXIT(psock) PT_EXIT(&((psock)->pt))
00298
00308 #define PSOCK_CLOSE_EXIT(psock) \
00309 do { \
00310 PSOCK_CLOSE(psock); \
00311 PSOCK_EXIT(psock); \
00312 } while(0)
00313
00325 #define PSOCK_END(psock) PT_END(&((psock)->pt))
00326
00327 char psock_newdata(struct psock *s);
00328
00339 #define PSOCK_NEWDATA(psock) psock_newdata(psock)
00340
00372 #define PSOCK_WAIT_UNTIL(psock, condition) \
00373 PT_WAIT_UNTIL(&((psock)->pt), (condition));
00374
00375 #define PSOCK_WAIT_THREAD(psock, condition) \
00376 PT_WAIT_THREAD(&((psock)->pt), (condition))
00377
00378 #endif
00379