NetBurner 3.5.0
PDF Version |
|
Typedefs | |
typedef void | FDCallBack(int fd, FDChangeType change, void *pData) |
Define the function signature for file descriptor notification callbacks. | |
Functions | |
int | close (int fd) |
Close the specified file descriptor and free the associated resources. | |
int | read (int fd, char *buf, int nbytes) |
Read data from a file descriptor (fd). | |
int | peek (int fd, char *c) |
Peek at the data for the specified file descriptor (fd). Will block forever until at least one byte is available to be read. The byte returned is not removed from the fd buffer, it will be the first byte of data returned on any subsequent read operation. | |
int | write (int fd, const char *buf, int nbytes) |
Write data to the stream associated with a file descriptor (fd). Can be used to write data to stdio, a TCP socket, or a Serial port. | |
int | writestring (int fd, const char *str) |
Write a null terminated ascii string to the stream associated with a file descriptor (fd). Can be used to write data to stdio, a TCP socket, or a Serial port. | |
int | writeall (int fd, const char *buf, int nbytes=0) |
Write the specified number of bytes to a file descriptor. Will block until all bytes are sent, or a file descriptor error occurs (such as a TCP socket error). Can be used to write data to stdio, a TCP socket, or a Serial port. | |
int | ReadWithTimeout (int fd, char *buf, int nbytes, unsigned long timeout) |
Read data from a file descriptor(fd), or return if at least one byte is not read within the specified timeout. Can be used instead of the read() function, which will block forever until at least one byte is read. File descriptors include such things as stdio, TCP sockets, TLS sockets, and Serial ports. | |
int | ReadWithTickTimeout (int fd, char *buf, int nbytes, TickTimeout &timeout) |
Same as ReadWithTimeout(), except the timeout value parameter is of type TickTimeout instead of an unsigned long. The TickTimeout object is more robust in terms of sequential timeout calls and rollover protection. | |
int | ReadAllWithTimeout (int fd, char *buf, int nbytes, unsigned long timeout) |
Attempt to read the specified number of bytes from a file descriptor, or return with the number of bytes read if the timeout value has expired. | |
int | ReadAllWithTickTimeout (int fd, char *buf, int nbytes, TickTimeout &timeout) |
Same as ReadWithTimeout(), except the timeout value parameter is of type TickTimeout instead of an unsigned long. The TickTimeout object is more robust in terms of sequential timeout calls and rollover protection. | |
int | readall (int fd, char *buf, int nbytes) |
Read the specified number of bytes from a file descriptor (fd). This function will block until either the requested number of bytes have been read, or a file descriptor error occurs. It can be used to read from stdio, TCP sockets, or Serial ports. | |
int | PeekWithTimeout (int fd, char *c, unsigned long timeout) |
This function peeks at data from a file descriptor (fd), with a specified timeout value (as opposed to the peek function which will block forever until at least one byte is available to be read). This function can be used to peek from stdio, TCP sockets, or Serial ports. | |
int | getchar () |
Get a character from stdin. Will block if no character is available, from stdio library. The default stdin is the debug serial port. | |
int | dataavail (int fd) |
Check the specified file descriptor to detmeine if data is available to be read. | |
int | writeavail (int fd) |
Check the specified file descriptor to determine data can be written. | |
int | haserror (int fd) |
Check if a file descriptor has an error. | |
int | charavail () |
Checks to see if data is available for read on stdin. By default, stdin is the boot/debug serial port. | |
void | RegisterFDCallBack (int fd, FDCallBack *fp, void *pData) |
Register a callback function to receive notification when an FD state changes. Register a NULL fp to remove the notification. | |
void | FD_ZERO (fd_set *pfds) |
Clear (set to 0) a fd_set (file descriptor set) so no file descriptors (fds) are selected. | |
void | FD_CLR (int fd, fd_set *pfds) |
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function clears or removes a specific file descriptor in an fd_set. | |
void | FD_SET (int fd, fd_set *pfds) |
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function sets or adds a specific file descriptor to an fd_set. | |
int | FD_ISSET (int fd, fd_set *pfds) |
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function checks whether or not a particular fd is set in the specified fd_set. | |
int | FD_OVERLAP (const fd_set *f1, const fd_set *f2) |
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function determines whether there exists a common file descriptor between the two sets. | |
void | FD_COPY (const fd_set *from, fd_set *to) |
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function copies one file descriptor set to another. | |
void | FD_SETFROMSET (const fd_set *from, fd_set *to) |
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function adds the file descriptors from one set to another. | |
void | FD_CLRFROMSET (const fd_set *from, fd_set *to) |
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function remove the file descriptors in one set from another. | |
int | select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, unsigned long timeout) |
Wait for events to occur on one or more I/O resources associated with a set of file descriptors (fds), such as data available to be read, a resource is available to write data, or an error has occurred. | |
int | ZeroWaitSelect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds) |
Returns whether events have occurred on one or more I/O resources associated with a set of file descriptors (fds), and returns immediately. | |
int | ioctl (int fd, int cmd) |
This function controls the selection of input/output control options for stdio: stdin = 0, stdout = 1 and stderr = 2. | |
int | ReplaceStdio (int stdio_fd, int new_fd) |
Maps stdio to any file descriptor (fd). | |
int | CurrentStdioFD (int stdio_fd) |
Returns the current file descriptor mapped to the stdio file descriptor. | |
void | IrqStdio () |
Open the system default serial port in interrupt mode using the system default baud rate, and assign this serial port to stdin, stdout and stderr. | |
FD Change Type | |
The notifications that a registered FD monitor can receive. | |
enum | FDChangeType { eReadSet , eWriteSet , eErrorSet , eClosingNow } |
The notifications that a registered FD monitor can receive. More... | |
I/O Control Options | |
The legal options for use with ioctl() and in conjunction with ioctlCmdFlags | |
#define | IOCTL_TX_CHANGE_CRLF (1) |
When set, transmitted char \n gets converted to \r\n | |
#define | IOCTL_RX_CHANGE_CRLF (2) |
When set, received \r\n get turned into \n | |
#define | IOCTL_RX_PROCESS_EDITS (4) |
When set, process backspace and do simple line editing. | |
#define | IOCTL_RX_ECHO (8) |
When set, echo chars received to tx. | |
#define | IOCTL_TX_NO_BLOCK (32) |
When set, stdout and stderr will drop output instead of blocking. | |
#define | IOCTL_ALL_OPTIONS (15) |
When set, turns on all options. | |
I/O Control Command Flags | |
The command flags to use in contuction with ioctl() and ioctlOptions | |
#define | IOCTL_SET (0x4000) |
Set an option. | |
#define | IOCTL_CLR (0x2000) |
Clear an option. | |
#include< iosys.h >
I/O system functions use file descriptors for communication and status of network interfaces, serial interfaces, and any custom file descriptors created by an application.
typedef void FDCallBack(int fd, FDChangeType change, void *pData) |
#include <iosys.h>
Define the function signature for file descriptor notification callbacks.
fd | The file descriptor number |
change | The reason for the call back, FDChangeType |
*pData | A void pointer passed into the register function. Can be used to reference objects or other data |
enum FDChangeType |
#include <iosys.h>
The notifications that a registered FD monitor can receive.
int charavail | ( | ) |
#include <iosys.h>
Checks to see if data is available for read on stdin. By default, stdin is the boot/debug serial port.
1 | Data available |
0 | No data available |
int close | ( | int | fd | ) |
#include <iosys.h>
Close the specified file descriptor and free the associated resources.
fd | The file descriptor number |
int CurrentStdioFD | ( | int | stdio_fd | ) |
#include <iosys.h>
Returns the current file descriptor mapped to the stdio file descriptor.
stdio_fd | The stdio file descriptor to check. Options are stdin (0), stdout (1), and stderr (2). |
int dataavail | ( | int | fd | ) |
#include <iosys.h>
Check the specified file descriptor to detmeine if data is available to be read.
fd | The file descriptor number |
1 | Data available |
0 | No data available |
void FD_CLR | ( | int | fd, |
fd_set * | pfds ) |
#include <iosys.h>
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function clears or removes a specific file descriptor in an fd_set.
fd | The file descriptor number |
*pfds | Pointer to the fd_set to modify |
void FD_CLRFROMSET | ( | const fd_set * | from, |
fd_set * | to ) |
#include <iosys.h>
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function remove the file descriptors in one set from another.
*from | Pointer to the fd_set defining which file descriptors to remove. |
*to | Pointer to the fd_set containing file descritpors to remove. |
void FD_COPY | ( | const fd_set * | from, |
fd_set * | to ) |
#include <iosys.h>
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function copies one file descriptor set to another.
*from | Pointer to the file descriptor set being copied from. |
*to | Pointer to the fd_set to copy to. |
int FD_ISSET | ( | int | fd, |
fd_set * | pfds ) |
#include <iosys.h>
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function checks whether or not a particular fd is set in the specified fd_set.
For example:
fd | The file descriptor number |
*pfds | A pointer to the fd_set to test |
0 | File descriptor is not set in the file descriptor set |
>0 | File descriptor is set in the file descriptor set |
int FD_OVERLAP | ( | const fd_set * | f1, |
const fd_set * | f2 ) |
#include <iosys.h>
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function determines whether there exists a common file descriptor between the two sets.
*f1 | Pointer to the first file descriptor set. |
*f2 | Pointer to the second file descriptor set. |
void FD_SET | ( | int | fd, |
fd_set * | pfds ) |
#include <iosys.h>
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function sets or adds a specific file descriptor to an fd_set.
fd | The file descriptor number |
*pfds | Pointer to the fd_set to modify |
void FD_SETFROMSET | ( | const fd_set * | from, |
fd_set * | to ) |
#include <iosys.h>
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function adds the file descriptors from one set to another.
*from | Pointer to the file descriptor set being copied from. |
*to | Pointer to the fd_set to add to. |
void FD_ZERO | ( | fd_set * | pfds | ) |
#include <iosys.h>
Clear (set to 0) a fd_set (file descriptor set) so no file descriptors (fds) are selected.
*pfds | Pointer to the file descriptor set |
int getchar | ( | ) |
#include <iosys.h>
Get a character from stdin. Will block if no character is available, from stdio library. The default stdin is the debug serial port.
int haserror | ( | int | fd | ) |
#include <iosys.h>
Check if a file descriptor has an error.
fd | File descriptor number |
1 | The file descriptor has an error |
0 | The file descriptor does not have an error |
int ioctl | ( | int | fd, |
int | cmd ) |
#include <iosys.h>
This function controls the selection of input/output control options for stdio: stdin = 0, stdout = 1 and stderr = 2.
The legal options are listed in ioctlOptions.
fd | The file descriptor number. The three options are stdin (0), stdout (1), and stderr (2). |
cmd | The ioctl command options are ioctlCmdFlags and the bit of the associated options as defined by ioctlOptions. |
int peek | ( | int | fd, |
char * | c ) |
#include <iosys.h>
Peek at the data for the specified file descriptor (fd). Will block forever until at least one byte is available to be read. The byte returned is not removed from the fd buffer, it will be the first byte of data returned on any subsequent read operation.
fd | File descriptor |
*c | Pointer to the read destination character string |
int PeekWithTimeout | ( | int | fd, |
char * | c, | ||
unsigned long | timeout ) |
#include <iosys.h>
This function peeks at data from a file descriptor (fd), with a specified timeout value (as opposed to the peek function which will block forever until at least one byte is available to be read). This function can be used to peek from stdio, TCP sockets, or Serial ports.
The byte returned is not removed from the fd. The byte returned will be the first byte of data returned on the first subsequent read().
fd | The file descriptor number |
*c | A pointer to the read destination |
timeout | The number if time ticks to wait for at least 1 byte of data |
int read | ( | int | fd, |
char * | buf, | ||
int | nbytes ) |
#include <iosys.h>
Read data from a file descriptor (fd).
This function will block forever until at least one byte is available to be read from the input buffer of the specified file descriptor. To wait for a period of time if no data is immediately available in the buffer, please see ReadWithTimeout()
File descriptors include: TCP, UDP, Serial and Extra File Descriptors (EFD). EFDs can be used for custom purposes, such as reading/writing to buffers, or any periperal custom to your application.
The function will return the number of bytes read, or a negative number if there is an error condition. The error value depends on the type of file descriptor, such as TCP or Serial:
fd | The file descriptor number. |
*buf | Pointer to the read data destination. |
nbytes | Maximum number of bytes to read. |
int readall | ( | int | fd, |
char * | buf, | ||
int | nbytes ) |
#include <iosys.h>
Read the specified number of bytes from a file descriptor (fd). This function will block until either the requested number of bytes have been read, or a file descriptor error occurs. It can be used to read from stdio, TCP sockets, or Serial ports.
fd | File descriptor |
*buf | Pointer to the read destination buffer |
nbytes | Number of bytes to read |
int ReadAllWithTickTimeout | ( | int | fd, |
char * | buf, | ||
int | nbytes, | ||
TickTimeout & | timeout ) |
#include <iosys.h>
Same as ReadWithTimeout(), except the timeout value parameter is of type TickTimeout instead of an unsigned long. The TickTimeout object is more robust in terms of sequential timeout calls and rollover protection.
This function can be used to read from stdio, TCP sockets, or Serial ports. This function will block until on of the following conditions occurs:
fd | The file descriptor number |
*buf | A pointer to the read destination |
nbytes | Number of bytes to read |
timeout | A reference to the timeout value of type TickTimeout. |
int ReadAllWithTimeout | ( | int | fd, |
char * | buf, | ||
int | nbytes, | ||
unsigned long | timeout ) |
#include <iosys.h>
Attempt to read the specified number of bytes from a file descriptor, or return with the number of bytes read if the timeout value has expired.
This function can be used to read from stdio, TCP sockets, or Serial ports. This function will block until on of the following conditions occurs:
fd | The file descriptor number |
*buf | A pointer to the read destination |
nbytes | Number of bytes to read |
timeout | The number of timer ticks to wait for data |
int ReadWithTickTimeout | ( | int | fd, |
char * | buf, | ||
int | nbytes, | ||
TickTimeout & | timeout ) |
#include <iosys.h>
Same as ReadWithTimeout(), except the timeout value parameter is of type TickTimeout instead of an unsigned long. The TickTimeout object is more robust in terms of sequential timeout calls and rollover protection.
fd | The file descriptor number. |
*buf | A pointer to the read destination. |
nbytes | Maximum number of bytes to read. |
timeout | A reference to the timeout value of type TickTimeout. |
int ReadWithTimeout | ( | int | fd, |
char * | buf, | ||
int | nbytes, | ||
unsigned long | timeout ) |
#include <iosys.h>
Read data from a file descriptor(fd), or return if at least one byte is not read within the specified timeout. Can be used instead of the read() function, which will block forever until at least one byte is read. File descriptors include such things as stdio, TCP sockets, TLS sockets, and Serial ports.
fd | The file descriptor number. |
*buf | A pointer to the read destination. |
nbytes | Maximum number of bytes to read. |
timeout | The number of timer ticks to wait for data. |
void RegisterFDCallBack | ( | int | fd, |
FDCallBack * | fp, | ||
void * | pData ) |
#include <iosys.h>
Register a callback function to receive notification when an FD state changes. Register a NULL fp to remove the notification.
fd | The file descriptor number |
*fp | The function pointer to call back |
*pData | A void * passed to the callback function, can be used for any purpose, such as object references |
int ReplaceStdio | ( | int | stdio_fd, |
int | new_fd ) |
#include <iosys.h>
Maps stdio to any file descriptor (fd).
If the file descriptor generates an error (such as a closed TCP connection), then stdio will be remapped to a negative fd (this will cause stdio to generate errors). When this function is used to remap a stdio channel that has errored, then the error will be cleared.
stdio_fd | The stdio file descriptor to map to. Options are stdin (0), stdout (1), and stderr (2). |
new_fd | The file descriptor to replace stdio with. A value of 0 returns stdio to the default debug monitor based traps. |
0 | If stdio had not been previously mapped |
>0 | The value of the fd for the previous stdio override |
int select | ( | int | nfds, |
fd_set * | readfds, | ||
fd_set * | writefds, | ||
fd_set * | errorfds, | ||
unsigned long | timeout ) |
#include <iosys.h>
Wait for events to occur on one or more I/O resources associated with a set of file descriptors (fds), such as data available to be read, a resource is available to write data, or an error has occurred.
The most common use for this function is to monitor multiple serial and/or TCP file descriptors at one time to read incoming data. For example, an application could use a single RTOS task and a select() to process incoming data on multiple TCP sockets at one time, instead of using multiple tasks or looping through each fd sequentially.
The file descriptors of interest are specified with file descriptor sets (fds) for read, write and error conditions. select() will block until one of the fd conditions are true, or the specified timeout occurs (a value of 0 blocks forever). For example, if the readfds is used for multiple TCP sockets, select() will return if data is available to read on one or more of them. The application would then use macros such as FD_ISSET() to handle reading the data.
nfds | The number of file descriptors to examine (This parameter is currently ignored) |
*readfds | Pointer to the fd_set to select for read events, or null if no read events are to be monitored. It is modified on exit to reflect the read availability of the selected fds in the set. |
*writefds | Pointer to the fd_set to select for write availability events, or null if no events are to be monitored. If non-null, it is modified on exit to reflect the write availability of the selected fds in the set. |
*errorfds | Pointer to the fd_set to select for error events, or null if no error events are to be monitored. It is modified on exit to reflect the error state of the selected fds in the set. |
timeout | The number of system time ticks to wait before timing out if no events occurred in the selected fd sets. Note: The TICKS_PER_SECOND multiplier should be used to specify the timeout in seconds. For example, TICKS_PER_SECOND * 5 to specify a timeout of 5 seconds. |
0 | Timeout occurred |
>0 | The number of fds in all of the non-null fd_sets |
int write | ( | int | fd, |
const char * | buf, | ||
int | nbytes ) |
#include <iosys.h>
Write data to the stream associated with a file descriptor (fd). Can be used to write data to stdio, a TCP socket, or a Serial port.
fd | File descriptor |
*buf | Pointer to the buffer to write |
nbytes | Maximum number of bytes to write |
int writeall | ( | int | fd, |
const char * | buf, | ||
int | nbytes = 0 ) |
#include <iosys.h>
Write the specified number of bytes to a file descriptor. Will block until all bytes are sent, or a file descriptor error occurs (such as a TCP socket error). Can be used to write data to stdio, a TCP socket, or a Serial port.
fd | File descriptor |
*buf | Pointer to the buffer to write |
nbytes | Maximum number of bytes to write |
int writeavail | ( | int | fd | ) |
#include <iosys.h>
Check the specified file descriptor to determine data can be written.
fd | File descriptor number |
1 | Data can be written |
0 | Data cannot be written, such as when an output buffer if full |
int writestring | ( | int | fd, |
const char * | str ) |
#include <iosys.h>
Write a null terminated ascii string to the stream associated with a file descriptor (fd). Can be used to write data to stdio, a TCP socket, or a Serial port.
fd | File descriptor |
*str | Pointer to the null terminated string to write |
int ZeroWaitSelect | ( | int | nfds, |
fd_set * | readfds, | ||
fd_set * | writefds, | ||
fd_set * | errorfds ) |
#include <iosys.h>
Returns whether events have occurred on one or more I/O resources associated with a set of file descriptors (fds), and returns immediately.
nfds | The number of file descriptors to examine. Note: This parameter is currently ignored. |
*readfds | A pointer to the fd_set to select for read events. Note: This parameter can be NULL. It is modified on exit to reflect the read availability of the selected fds in the set. |
*writefds | A pointer to the fd_set to select for write availability events. Note: This parameter can be NULL. It is modified on exit to reflect the write availability of the selected fds in the set. |
*errorfds | A pointer to the fd_set to select for error events. Note: This parameter can be NULL. It is modified on exit to reflect the error state of the selected fds in the set. |
0 | If there is no valid fds |
>0 | The number of fds in all of the non null fd_sets |