mtcp_ppeek

NAME

mtcp_ppeek − Peek into the bytestream from a monitoring socket from a given offset

SYNOPSIS

#include <mos_api.h>

ssize_t mtcp_ppeek(mctx_t mctx, int sockid, int side, char *buf, size_t len, uint64_t off);

DESCRIPTION

mtcp_ppeek() can be used to peek up to len number of bytes from a monitoring socket via socket descriptor sockid into the buffer starting at buf. from off ; value which is the offset distance (in bytes) from the TCP initial sequence number. It is the responsibility of the user to allocate memory for buf array.

For cases when the total number of buffered unread bytes in the socket are less than len, mtcp_ppeek() copies entire data to buf and returns the actual number of bytes that can be used by the application.

Note that the off can also point to the data in the fragmented buffer list of the TCP ring buffer (see mtcp_getsockopt()). If there is no received byte at off in the TCP ring buffer, it returns error. If there are received bytes starting from off , len is set to be the number of bytes read from the buffer. After mtcp_ppeek(), the data in the TCP ring buffer will not be flushed, and the monitor offset used by mtcp_peek() is not changed.

An mtcp_ppeek() call takes two additional argument named mctx , that represents the per-core mTCP context in an application (see mtcp_create_context() for details); and side that informs the stack whether it needs to peek the client (MOS_SIDE_CLI) or server (MOS_SIDE_SVR) side.

RETURN VALUE

On success, the number of bytes read is returned. It is not an error if this number is smaller than the number of bytes requested; this may happen when the socket has fewer number of bytes buffered at that moment. On all errors, -1 is returned and errno is set appropriately.

ERRORS

EACCES

The mctx argument is invalid.

EBADF

The socket descriptor sockid is invalid.

EINVAL

The buffer management of the monitoring socket with sockid was already disabled.

ESOCKTNOSUPPORT

The socket referred to by sockid has invalid type

ENOTCONN

Th socket referred to by sockid is in a TCP state that disallows read operations.

ENODATA

The socket referred to by sockid does not have any available bytes in its buffer for reading.

EPERM

The caller is not permitted to access this function.

AUTHORS

mOS development team <mtcp-user@list.ndsl.kaist.edu>

EXAMPLES

http://mos.kaist.edu/guide/programmer/05_api_example.html#monitoring-reassembled-tcp-payload

SEE ALSO

mtcp_peek(), mtcp_socket(),

COLOPHON

This page is part of mOS release 0.3 docs section. A description of the project, and information about reporting bugs, can be found at http://mos.kaist.edu/.