Project 1 - Peer-to-peer and interface protocols using C  1.0
A half-duplex layered communication system.
 All Classes Files Functions Macros
Macros | Functions
layer1.c File Reference

Layer 1 maintains byte ordering such that the receiver receives the first byte sent before receiving the second byte, etc. More...

#include "layer.h"

Functions

int layer1_write (char b)
 Sample layer1_write just calls write to stdout. More...
 
int layer1_read (char *b)
 Sample layer1_read just calls read on stdin. More...
 

Detailed Description

Layer 1 maintains byte ordering such that the receiver receives the first byte sent before receiving the second byte, etc.

Sample layer 1 implementation - this can be used to provide half-duplex communication by using the shell to create a pipe between a sender process and a receiver process.

Peer-to-peer and Interface Protocols Using C

Author
Nicholas Guthrie guthr.nosp@m.n@rp.nosp@m.i.edu http//nickguthrie.com January 30, 2014

Compile with: gcc -c layer1.c -o ../build/layer1.o

Function Documentation

int layer1_read ( char *  b)

Sample layer1_read just calls read on stdin.

Parameters
[in]b
Returns
The number of bytes read: 1 if everything goes well. -1 if there was an error.
int layer1_write ( char  b)

Sample layer1_write just calls write to stdout.

A chunk :: a sequence of bytes whose length is no greater than 16 bytes

  • Each of the bytes in a chunk can have any value, including binary data and the '\0' character; only restriction is there are no more than 16 bytes.
  • Note that it is also valid to send/receive a chunk of size 0. TODO List
  • Add check function that checks max length vs actual length (const)
Parameters
[in]b
Returns
The number of bytes written: 1 if everything goes well. -1 if there was an error.