|
Qsmtp
0.23svn
|
functions for network I/O More...
#include <sys/select.h>#include <unistd.h>#include <errno.h>#include <string.h>#include <assert.h>#include "netio.h"#include "log.h"#include "ssl_timeoutio.h"#include "tls.h"Defines | |
| #define | DEBUG_IN(l) {} |
| #define | DEBUG_OUT(s, l) {} |
Functions | |
| int | net_read (void) |
| int | netwrite (const char *s) |
| int | netnwrite (const char *s, const size_t l) |
| int | net_writen (const char *const *s) |
| int | net_write_multiline (const char *const *s) |
| size_t | net_readbin (size_t num, char *buf) |
| size_t | net_readline (size_t num, char *buf) |
| int | data_pending (void) |
Variables | |
| char | linein [1002] |
| size_t | linelen |
| time_t | timeout |
functions for network I/O
| int data_pending | ( | void | ) |
check if there is data ready to be read without blocking
| 0 | if no data |
| 1 | if data |
| -1 | on error |
| int net_read | ( | void | ) |
read one line from the network
| 0 | on success |
| -1 | on error (errno is set) |
does not return on timeout, programm 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)
| num | number of bytes to read |
| buf | buffer to store data (must have enough space for (num + 1) bytes) |
| -1 | on error |
| 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
| 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) |
| -1 | on error |
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
| s | array of strings to send |
| 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, programm 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
| s | array of strings to send |
| 0 | on success |
| -1 | on error (errno is set) |
does not return on timeout, programm will be cancelled
| int netnwrite | ( | const char * | s, |
| const size_t | l | ||
| ) |
write one line to the network
| s | line to be written (nothing else it written so it should contain CRLF) |
| l | length of s |
| 0 | on success |
| -1 | on error (errno is set) |
does not return on timeout, programm will be cancelled
| int netwrite | ( | const char * | s | ) |
write one line to the network
| s | line to be written (nothing else it written so it should contain CRLF) |
| 0 | on success |
| -1 | on error (errno is set) |
-does not return on timeout, programm will be cancelled -same as net_write but expects that line is <= 512 characters and includes CRLF
| char linein[1002] |
buffer for the line to read: max 1000 chars including CRLF, leading extra '.', closing '\0'
| size_t linelen |
length of the line
| time_t timeout |
how long to wait for data
1.7.6.1