functions for network I/O
More...
#include "sstring.h"
#include <string.h>
#include <sys/types.h>
#include <time.h>
Go to the source code of this file.
functions for network I/O
Enumerator |
---|
shutdown_clean |
do a normal shutdown and notify the partner about the shutdown
|
shutdown_abort |
do hard abort of connection
|
int data_pending |
( |
void |
| ) |
|
check if there is data ready to be read without blocking
- Returns
- if there is data available
- Return values
-
0 | if no data |
1 | if data |
<0 | error code |
This will return -ECONNRESET if the connection has been closed by the remote end.
shutdown the connection and end the program
- Parameters
-
sd_type | specifies the way the shutdown should be performed |
This is a forward declaration only, every program has to implement this function in a way that matches how it works.
A shutdown_clean shutdown is e.g. sending QUIT to the server and waiting for it's reply. A shutdown with shutdown_abort is e.g. hard dropping of the connection if the client sends spam and has a broken SMTP engine that does not react to error codes.
Calling this function even before the connection was established is fine.
int net_read |
( |
const int |
fatal | ) |
|
read one line from the network
- Parameters
-
fatal | if connection errors should lead to program termination |
- Return values
-
0 | on success |
-1 | on error (errno is set) |
does not return on timeout, program will be cancelled
size_t net_readbin |
( |
size_t |
num, |
|
|
char * |
buf |
|
) |
| |
read a given number of bytes from network as binary data (i.e. without any mangling)
- Parameters
-
num | number of bytes to read |
buf | buffer to store data (must have enough space for (num + 1) bytes) |
- Returns
- number of bytes read
- Return values
-
size_t net_readline |
( |
size_t |
num, |
|
|
char * |
buf |
|
) |
| |
read up to a given number of bytes from network but stop at the first CRLF
- Parameters
-
num | number of bytes to read, must be < 1002 so everything behind the CRLF can be copied back to lineinn |
buf | buffer to store data (must have enough space) |
- Returns
- number of bytes read
- Return values
-
The trailing CRLF sequence is kept in the buffer. This function will return an error if it detects a bare CR or LF in the middle of the input data, but it cannot detect if the CR goes in one call and LF in the next, so it will allow the output to be just LF or to end in CR.
int net_write_multiline |
( |
const char *const * |
s | ) |
|
write multiple lines to the network
- Parameters
-
s | array of strings to send |
- Return values
-
0 | on success |
-1 | on error (errno is set) |
This combines all given strings into one buffer and send them out to the network. This allows the underlying network stack to use the least sensible number of packets, reducing network latency. If memory allocation fails for the intermediate buffer the lines may be send in smaller chunks, which is less efficient but is no other loss in functionality.
Does not return on timeout, program will be cancelled.
If one part or multiple consecutive parts covers a whole SMTP line this line must conform to the SMTP line length limit (512 bytes).
int net_writen |
( |
const char *const * |
s | ) |
|
write one line to the network, fold if needed
- Parameters
-
s | array of strings to send |
- Return values
-
0 | on success |
-1 | on error (errno is set) |
does not return on timeout, program will be cancelled
- Warning
- s[0] must be short enough to fit completely into the buffer
-
s[0] must contain the whole status code as well as the following space (' ') or hyphen ('-')
-
every s[] must not have a sequence longer then 506 characters without a space (' ') in them
int netnwrite |
( |
const char * |
s, |
|
|
const size_t |
l |
|
) |
| |
write one line to the network
- Parameters
-
s | line to be written (nothing else it written so it should contain CRLF) |
l | length of s |
- Return values
-
0 | on success |
-1 | on error (errno is set) |
does not return on timeout, program will be cancelled
the descriptor where messages to network are written to
how long to wait for data