forked from miftahulmahfuzh/slidingwindowprotocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceiver.h
75 lines (61 loc) · 1.61 KB
/
receiver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* File : dcomm.h
*/
#ifndef _RECEIVER_H_
#define _RECEIVER_H_
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
/* ASCII Const */
#define SOH 1 /* Start of Header Character */
#define STX 2 /* Start of Text Character */
#define ETX 3 /* End of Text Character */
#define ENQ 5 /* Enquiry Character */
#define ACK 6 /* Acknowledgement */
#define BEL 7 /* Message Error Warning */
#define CR 13 /* Carriage Return */
#define LF 10 /* Line Feed */
#define NAK 21 /* Negative Acknowledgement */
#define Endfile 26 /* End of file character */
#define ESC 27 /* ESC key */
/* XON/XOFF protocol */
#define XON (0x11)
#define XOFF (0x13)
/* Const */
#define BYTESIZE 256 /* The maximum value of a byte */
#define MAXLEN 1024 /* Maximum messages length */
#define MIN_UPPERLIMIT 5
#define MAX_LOWERLIMIT 2
#define bzero(p, size) (void)memset((p), 0 , (size))
/* Delay to adjust speed of consuming buffer, in milliseconds */
#define DELAY 500
/* Define receive buffer size */
#define RXQSIZE 8
typedef unsigned char Byte;
typedef struct QTYPE {
unsigned int count;
unsigned int front;
unsigned int rear;
unsigned int maxsize;
Byte *data;
} QTYPE;
typedef struct MESGB {
unsigned int soh;
unsigned int stx;
unsigned int etx;
Byte checksum;
Byte msgno;
Byte *data;
} MESGB;
/* FUNCTIONS AND PROCEDURES */
static Byte *rcvchar(int sockfd, QTYPE *queue);
static Byte *q_get(QTYPE *, Byte *);
void *childRProcess(void * threadid);
void error(const char* message);
#endif