43 #define STATE_BLOCKED_NEWDATA 3
44 #define STATE_BLOCKED_CLOSE 4
45 #define STATE_BLOCKED_SEND 5
46 #define STATE_DATA_SENT 6
53 #define BUF_NOT_FULL 0
54 #define BUF_NOT_FOUND 0
72 buf_setup(
struct psock_buf *buf,
73 u8_t *bufptr, u16_t bufsize)
80 buf_bufdata(
struct psock_buf *buf, u16_t len,
81 u8_t **dataptr, u16_t *datalen)
83 if(*datalen < buf->left) {
84 memcpy(buf->ptr, *dataptr, *datalen);
86 buf->left -= *datalen;
90 }
else if(*datalen == buf->left) {
91 memcpy(buf->ptr, *dataptr, *datalen);
98 memcpy(buf->ptr, *dataptr, buf->left);
99 buf->ptr += buf->left;
100 *datalen -= buf->left;
101 *dataptr += buf->left;
112 while(buf->left > 0 && *datalen > 0) {
113 c = *buf->ptr = **dataptr;
125 return BUF_NOT_FOUND;
128 while(*datalen > 0) {
134 return BUF_FOUND | BUF_FULL;
147 if(s->state != STATE_DATA_SENT ||
uip_rexmit()) {
153 s->state = STATE_DATA_SENT;
155 }
else if(s->state == STATE_DATA_SENT &&
uip_acked()) {
160 s->sendptr += s->sendlen;
163 s->state = STATE_ACKED;
184 s->state = STATE_NONE;
188 while(s->sendlen > 0) {
197 s->state = STATE_NONE;
203 unsigned short (*generate)(
void *),
void *arg))
208 if(generate ==
NULL) {
212 s->state = STATE_NONE;
216 s->sendlen = generate(arg);
224 s->state = STATE_DATA_SENT;
231 s->state = STATE_NONE;
239 return psock->bufsize - psock->buf.left;
243 psock_newdata(
struct psock *s)
249 }
else if(s->state == STATE_READ) {
251 s->state = STATE_BLOCKED_NEWDATA;
266 buf_setup(&psock->buf, psock->bufptr, psock->bufsize);
272 if(psock->readlen == 0) {
274 psock->state = STATE_READ;
278 }
while((buf_bufto(&psock->buf, c,
280 &psock->readlen) & BUF_FOUND) == 0);
282 if(psock_datalen(psock) == 0) {
283 psock->state = STATE_NONE;
293 buf_setup(&psock->buf, psock->bufptr, psock->bufsize);
300 if(psock->readlen == 0) {
302 psock->state = STATE_READ;
306 }
while(buf_bufdata(&psock->buf, psock->bufsize,
307 &psock->readptr, &psock->readlen) == BUF_NOT_FULL &&
308 psock_datalen(psock) < len);
310 if(psock_datalen(psock) == 0) {
311 psock->state = STATE_NONE;
320 uint8_t *buffer,
unsigned int buffersize)
322 psock->state = STATE_NONE;
324 psock->bufptr = buffer;
325 psock->bufsize = buffersize;
326 buf_setup(&psock->buf, buffer, buffersize);