ceptr
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
stream.h File Reference

streams abstraction header file More...

#include <stdio.h>
#include <pthread.h>
#include <stdbool.h>
Include dependency graph for stream.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Stream
 
struct  SocketListener
 
#define DEFAULT_READER_BUFFER_SIZE   1000
 
#define _st_new_unix_stream(s, r)   __st_new_unix_stream(s,r?DEFAULT_READER_BUFFER_SIZE:0)
 
#define __st_init_scan(s)   s->scan_state = StreamScanInitial
 
#define __st_buf_full(s)   (s->bytes_used == s->buf_size)
 
#define _st_is_alive(st)   ((st->flags & StreamAlive) || (st->flags & StreamReader && (st->scan_state != StreamScanComplete)))
 
#define _st_data(st)   (&(st)->buf[st->unit_start])
 
#define _st_data_size(st)   (st)->unit_size
 
enum  StreamTypes { UnixStream, SocketStream }
 
enum  {
  StreamHasData =0x0001, StreamCloseOnFree =0x0002, StreamReader =0x0004, StreamWaiting =0x0008,
  StreamAlive =0x8000, StreamCloseAfterOneWrite =0x0010, StreamDying =0x0100, StreamLoadByLine =0x0200
}
 
enum  ScanStates { StreamScanInitial, StreamScanSuccess, StreamScanPartial, StreamScanComplete }
 
typedef struct Stream Stream
 
typedef void(* hasDataCallbackFn )(Stream *)
 
typedef struct SocketListener SocketListener
 
typedef void(* lisenterConnectionCallbackFn )(Stream *, void *)
 
char * DELIM_LF
 
char * DELIM_CRLF
 
Stream__st_new_unix_stream (FILE *stream, size_t reader_buffer_size)
 
Stream__st_alloc_stream ()
 
size_t __st_unix_stream_load (Stream *st)
 
void __st_scan (Stream *st)
 
SocketListener_st_new_socket_listener (int port, lisenterConnectionCallbackFn fn, void *callback_arg, char *delim)
 
void _st_close_listener (SocketListener *l)
 
void _st_start_read (Stream *st)
 
void _st_data_consumed (Stream *st)
 
void _st_kill (Stream *st)
 
void _st_free (Stream *)
 
int _st_write (Stream *stream, char *buf, size_t len)
 
int _st_writeln (Stream *stream, char *buf)
 

Detailed Description

streams abstraction header file

Definition in file stream.h.

Function Documentation

Stream* __st_new_unix_stream ( FILE *  stream,
size_t  reader_buffer_size 
)

create a new stream object of the unix file flavor

if the the stream is a read stream you must pass in a starting buffer size

Definition at line 300 of file stream.c.

void __st_scan ( Stream st)

scan a stream's buffer for a unit

currently a unit simply is defined by a new-line char

Todo:
allow other delimiters, or even simply a length, to mark off a unit.

Definition at line 125 of file stream.c.

size_t __st_unix_stream_load ( Stream st)

load file data into the stream buffer

returns the number of bytes loaded if 0 bytes loaded, st->err will hold the reason, which is either because and EndOfFile condition, or a some other unix error (from errno)

if the buffer is already full when this function is called, it will attempt to increase the buffer size with a realloc before reading.

Definition at line 49 of file stream.c.

void _st_close_listener ( SocketListener l)

close a socket listener

Definition at line 444 of file stream.c.

void _st_data_consumed ( Stream st)

mark that data in a stream has been consumed

Definition at line 470 of file stream.c.

void _st_free ( Stream st)

release the resources of a stream object

Definition at line 507 of file stream.c.

void _st_kill ( Stream st)

kill a stream

if a reader stream is blocked and waiting, calls _st_start_read so that the reader thread can complete.

Definition at line 481 of file stream.c.

SocketListener* _st_new_socket_listener ( int  port,
lisenterConnectionCallbackFn  fn,
void *  callback_arg,
char *  delim 
)

create a socket listener on a port which will generate socket streams when connections arrive

Definition at line 372 of file stream.c.

void _st_start_read ( Stream st)

wake the stream reader thread

Definition at line 455 of file stream.c.

int _st_write ( Stream st,
char *  buf,
size_t  len 
)

write to a stream

Definition at line 534 of file stream.c.

int _st_writeln ( Stream stream,
char *  str 
)

write a line to a stream using the delim as the EOL

Definition at line 563 of file stream.c.