42 #define STATE_BLOCKED_NEWDATA 3
43 #define STATE_BLOCKED_CLOSE 4
44 #define STATE_BLOCKED_SEND 5
45 #define STATE_DATA_SENT 6
52 #define BUF_NOT_FULL 0
53 #define BUF_NOT_FOUND 0
71 buf_setup(
struct psock_buf *buf,
72 uint8_t *bufptr, uint16_t bufsize)
79 buf_bufdata(
struct psock_buf *buf, uint16_t len,
80 uint8_t **dataptr, uint16_t *datalen)
82 if(*datalen < buf->left) {
83 memcpy(buf->ptr, *dataptr, *datalen);
85 buf->left -= *datalen;
89 }
else if(*datalen == buf->left) {
90 memcpy(buf->ptr, *dataptr, *datalen);
97 memcpy(buf->ptr, *dataptr, buf->left);
98 buf->ptr += buf->left;
99 *datalen -= buf->left;
100 *dataptr += buf->left;
111 while(buf->left > 0 && *datalen > 0) {
112 c = *buf->ptr = **dataptr;
124 return BUF_NOT_FOUND;
136 if(s->state != STATE_DATA_SENT ||
uip_rexmit()) {
142 s->state = STATE_DATA_SENT;
144 }
else if(s->state == STATE_DATA_SENT &&
uip_acked()) {
149 s->sendptr += s->sendlen;
152 s->state = STATE_ACKED;
173 s->state = STATE_NONE;
177 while(s->sendlen > 0) {
186 s->state = STATE_NONE;
192 unsigned short (*generate)(
void *),
void *arg))
197 if(generate ==
NULL) {
201 s->state = STATE_NONE;
205 s->sendlen = generate(arg);
213 s->state = STATE_DATA_SENT;
220 s->state = STATE_NONE;
228 return psock->bufsize - psock->buf.left;
232 psock_newdata(
struct psock *s)
238 }
else if(s->state == STATE_READ) {
240 s->state = STATE_BLOCKED_NEWDATA;
255 buf_setup(&psock->buf, psock->bufptr, psock->bufsize);
261 if(psock->readlen == 0) {
263 psock->state = STATE_READ;
267 }
while(buf_bufto(&psock->buf, c,
269 &psock->readlen) == BUF_NOT_FOUND);
271 if(psock_datalen(psock) == 0) {
272 psock->state = STATE_NONE;
282 buf_setup(&psock->buf, psock->bufptr, psock->bufsize);
289 if(psock->readlen == 0) {
291 psock->state = STATE_READ;
295 }
while(buf_bufdata(&psock->buf, psock->bufsize,
296 &psock->readptr, &psock->readlen) == BUF_NOT_FULL &&
297 psock_datalen(psock) < len);
299 if(psock_datalen(psock) == 0) {
300 psock->state = STATE_NONE;
309 uint8_t *buffer,
unsigned int buffersize)
311 psock->state = STATE_NONE;
313 psock->bufptr = buffer;
314 psock->bufsize = buffersize;
315 buf_setup(&psock->buf, buffer, buffersize);
CCIF void uip_send(const void *data, int len)
Send data on the current connection.
#define uip_newdata()
Is new incoming data available?
#define uip_mss()
Get the current maximum segment size that can be sent on the current connection.
#define NULL
The null pointer.
#define PT_INIT(pt)
Initialize a protothread.
#define PT_RESTART(pt)
Restart the protothread.
#define PT_THREAD(name_args)
Declaration of a protothread.
#define uip_acked()
Has previously sent data been acknowledged?
#define PT_WAIT_UNTIL(pt, condition)
Block and wait until condition is true.
Protosocket library header file.
The representation of a protosocket.
#define PT_BEGIN(pt)
Declare the start of a protothread inside the C function implementing the protothread.
#define CC_REGISTER_ARG
Configure if the C compiler supports the "register" keyword for function arguments.
#define uip_datalen()
The length of any incoming data that is currently available (if available) in the uip_appdata buffer...
#define PT_YIELD_UNTIL(pt, cond)
Yield from the protothread until a condition occurs.
#define PT_END(pt)
Declare the end of a protothread.
#define PT_EXIT(pt)
Exit the protothread.
uip_appdata
Pointer to the application data in the packet buffer.
#define uip_rexmit()
Do we need to retransmit previously data?