Unlike programs written for the ordinary uIP event-driven interface, programs written with the protosocket library are executed in a sequential fashion and does not have to be implemented as explicit state machines.
Protosockets only work with TCP connections.
The protosocket library uses Protothreads protothreads to provide sequential control flow. This makes the protosockets lightweight in terms of memory, but also means that protosockets inherits the functional limitations of protothreads. Each protosocket lives only within a single function. Automatic variables (stack variables) are not retained across a protosocket library function call.
Because each protosocket runs as a protothread, the protosocket has to be started with a call to PSOCK_BEGIN() at the start of the function in which the protosocket is used. Similarly, the protosocket protothread can be terminated by a call to PSOCK_EXIT().
Files | |
file | psock.h |
Protosocket library header file. | |
Data Structures | |
struct | psock_buf |
struct | psock |
The representation of a protosocket. More... | |
Defines | |
#define | PSOCK_INIT(psock, buffer, buffersize) |
Initialize a protosocket. | |
#define | PSOCK_BEGIN(psock) |
Start the protosocket protothread in a function. | |
#define | PSOCK_SEND(psock, data, datalen) |
Send data. | |
#define | PSOCK_SEND_STR(psock, str) |
Send a null-terminated string. | |
#define | PSOCK_GENERATOR_SEND(psock, generator, arg) |
Generate data with a function and send it. | |
#define | PSOCK_CLOSE(psock) |
Close a protosocket. | |
#define | PSOCK_READBUF(psock) |
Read data until the buffer is full. | |
#define | PSOCK_READTO(psock, c) |
Read data up to a specified character. | |
#define | PSOCK_DATALEN(psock) |
The length of the data that was previously read. | |
#define | PSOCK_EXIT(psock) |
Exit the protosocket's protothread. | |
#define | PSOCK_CLOSE_EXIT(psock) |
Close a protosocket and exit the protosocket's protothread. | |
#define | PSOCK_END(psock) |
Declare the end of a protosocket's protothread. | |
#define | PSOCK_NEWDATA(psock) |
Check if new data has arrived on a protosocket. | |
#define | PSOCK_WAIT_UNTIL(psock, condition) |
Wait until a condition is true. | |
#define | PSOCK_WAIT_THREAD(psock, condition) PT_WAIT_THREAD(&((psock)->pt), (condition)) |
Functions | |
u16_t | psock_datalen (struct psock *psock) |
char | psock_newdata (struct psock *s) |
|
Start the protosocket protothread in a function. This macro starts the protothread associated with the protosocket and must come before other protosocket calls in the function it is used.
|
|
Close a protosocket. This macro closes a protosocket and can only be called from within the protothread in which the protosocket lives.
|
|
Close a protosocket and exit the protosocket's protothread. This macro closes a protosocket and exits the protosocket's protothread.
|
|
The length of the data that was previously read. This macro returns the length of the data that was previously read using PSOCK_READTO() or PSOCK_READ().
|
|
Declare the end of a protosocket's protothread. This macro is used for declaring that the protosocket's protothread ends. It must always be used together with a matching PSOCK_BEGIN() macro.
|
|
Exit the protosocket's protothread. This macro terminates the protothread of the protosocket and should almost always be used in conjunction with PSOCK_CLOSE().
|
|
Generate data with a function and send it.
The generator function should place the generated data directly in the uip_appdata buffer, and return the length of the generated data. The generator function is called by the protosocket layer when the data first is sent, and once for every retransmission that is needed. |
|
Initialize a protosocket. This macro initializes a protosocket and must be called before the protosocket is used. The initialization also specifies the input buffer for the protosocket.
Definition at line 144 of file psock.h. Referenced by hello_world_appcall(), httpd_appcall(), and smtp_send(). |
|
Check if new data has arrived on a protosocket. This macro is used in conjunction with the PSOCK_WAIT_UNTIL() macro to check if data has arrived on a protosocket.
|
|
Read data until the buffer is full. This macro will block waiting for data and read the data into the input buffer specified with the call to PSOCK_INIT(). Data is read until the buffer is full..
|
|
Read data up to a specified character. This macro will block waiting for data and read the data into the input buffer specified with the call to PSOCK_INIT(). Data is only read until the specifieed character appears in the data stream.
|
|
Send data. This macro sends data over a protosocket. The protosocket protothread blocks until all data has been sent and is known to have been received by the remote end of the TCP connection.
|
|
Send a null-terminated string.
|
|
Wait until a condition is true. This macro blocks the protothread until the specified condition is true. The macro PSOCK_NEWDATA() can be used to check if new data arrives when the protosocket is waiting. Typically, this macro is used as follows:
PT_THREAD(thread(struct psock *s, struct timer *t)) { PSOCK_BEGIN(s); PSOCK_WAIT_UNTIL(s, PSOCK_NEWADATA(s) || timer_expired(t)); if(PSOCK_NEWDATA(s)) { PSOCK_READTO(s, '\n'); } else { handle_timed_out(s); } PSOCK_END(s); }
|