Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

block_receive.c File Reference

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <pthread.h>
#include <sys/time.h>
#include <unistd.h>
#include <sys/poll.h>
#include "libcomm.h"

Functions

void thread1 (struct LIBCOMMPTHREADS *libcommpthreads)
 This is a part of block_call() and must not called from the user. More...

int block_call (int fd, int id, int term, void(*block_call_do)(int fd, int id, unsigned int type, char *buf, unsigned int size, int term), void(*block_call_term)(int fd, int id))
 Start in thread, wait for a datablock and call the function block_call_do() if one was received or block_call_term() when the connection terminates. More...

int block_ifdata (int fd)
 This function tests if new data is available to read on a stream. More...

char * block_receive_poll (int fd, unsigned int *type, char *buf, unsigned int *size, unsigned int maxsize, int term)
 Test if is there data available on the socket and read it in a buffer if there is. More...

char * block_receive (int fd, unsigned int *type, char *buf, unsigned int *size, unsigned int maxsize, int term)
 Receive a block (composition of: type, size of datablock and datablock) from a socket. More...

int block_receive_integer (int fd, unsigned int *recvi)
 Receive an integer (two bytes; 16Bit) from the socket. More...

int block_receive_nbytes (int fd, char *buf, int n)
 Receive n bytes from socket. More...


Function Documentation

int block_call int    fd,
int    id,
int    term,
void(*    block_call_do)(int fd, int id, unsigned int type, char *buf, unsigned int size, int term),
void(*    block_call_term)(int fd, int id)
 

Start in thread, wait for a datablock and call the function block_call_do() if one was received or block_call_term() when the connection terminates.

Parameters:
fd  (int) descriptor of socket
id  (int) arbitrary id of background process / thread
term  (int) 0: do not terminate the buffer, 1: terminate the buffer by appending a 0x00.
block_call_do  (int fd, int id, unsigned int type, char *buf, unsigned int size, int term) (function) this function is called if a datablock was received. fd, id and term are the same as in block_call(). type describes the type of the received datablock, buf is a pointer to this datablock and size is the number of bytes of the datablock
block_call_term  (int fd, int id) (function) this function is called if the connection terminates. fd and id are the same as in block_call().
Returns:
If all right zero otherwise non zero.

int block_ifdata int    fd
 

This function tests if new data is available to read on a stream.

Parameters:
fd  (int) discriptor of stream to test
Returns:
(int) 1: Data to read; 0: No data to read

char* block_receive int    fd,
unsigned int *    type,
char *    buf,
unsigned int *    size,
unsigned int    maxsize,
int    term
 

Receive a block (composition of: type, size of datablock and datablock) from a socket.

WARNING: The integers (type and size; excluding fd) are only 16 bit values (0 - 65535).

Parameters:
fd  (int) descriptor of socket
type  (unsigned int *) pointer to integer, this value can be used as buyer's option
buf  (char *) buffer for datablock. Memory will be allocated if this parameter is equal to null.
size  (unsigned int *) pointer to integer in which the size of the received datablock is saved.
maxsize  (unsigned int *) describes size of buf. This parameter will be ignored if bus is equal to null.
term  (int) 0: do not terminate the buffer, 1: terminate the buffer by appending a 0x00.
Returns:
(char *) pointer to buffer which contains the received datablock; NULL if fail.

int block_receive_integer int    fd,
unsigned int *    recvi
 

Receive an integer (two bytes; 16Bit) from the socket.

Parameters:
fd  (int) descriptor of socket
recvi  (unsigned int *) pointer to integer in which the received integer is saved.
Returns:
(int) 2: OK; -1: fail

int block_receive_nbytes int    fd,
char *    buf,
int    n
 

Receive n bytes from socket.

Parameters:
fd  (integer) descriptor of socket
buf  (char *) buffer for saving the received bytes
n  (integer) number of bytes to receive
Returns:
(integer) n: OK; -1 fial

char* block_receive_poll int    fd,
unsigned int *    type,
char *    buf,
unsigned int *    size,
unsigned int    maxsize,
int    term
 

Test if is there data available on the socket and read it in a buffer if there is.

WARNING: The integers (type and size; excluding fd) are only 16 bit values (0 - 65535).

Parameters:
fd  (int) descriptor of socket
type  (unsigned int *) pointer to integer, this value can be used as buyer's option
buf  (char *) buffer for datablock. Memory will be allocated if this parameter is equal to null.
size  (unsigned int *) pointer to integer in which the size of the received datablock is saved.
maxsize  (unsigned int *) describes size of buf. This parameter will be ignored if bus is equal to null.
term  (int) 0: do not terminate the buffer, 1: terminate the buffer by appending a 0x00.
Returns:
(char *) pointer to buffer which contains the received datablock; NULL if fail; 1 if no data available.

void thread1 struct LIBCOMMPTHREADS   libcommpthreads
 

This is a part of block_call() and must not called from the user.

This function is the thread which is started from block_call() and runs in background.

Parameters:
libcommpthreads  (struct LIBCOMMPTHREADS *) holds pointers to the functions to be call, fd (socket discriptor) and id.


Generated on Thu Feb 17 10:17:23 2005 for FinalYearProject,A.Hofmeier:CommunicationLibrary by doxygen1.2.15