plptools
Loading...
Searching...
No Matches
link.h
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
5 * Copyright (C) 1999-2002 Fritz Elfert <felfert@to.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * along with this program; if not, see <https://www.gnu.org/licenses/>.
19 *
20 */
21#ifndef _link_h_
22#define _link_h_
23
24#include "config.h"
25#include <pthread.h>
26#include <sys/time.h>
27
28#include "bufferstore.h"
29#include "bufferarray.h"
30#include "Enum.h"
31#include <vector>
32
33class NCP;
34class packet;
35
40typedef struct {
44 int seq;
52 struct timeval stamp;
58
59extern "C" {
60 static void *expire_check(void *);
61}
62
63class Link {
64public:
65
66 enum link_type {
70 };
71
81 Link(const char *fname, int baud, NCP *ncp, unsigned short verbose, const int cancellationFd);
82
86 ~Link();
87
93 void send(const bufferStore &buff);
94
101 bool stuffToSend();
102
109 bool hasFailed();
110
114 void reset();
115
119 void flush();
120
127 void purgeQueue(int channel);
128
134 void setVerbose(unsigned short _verbose);
135
142 unsigned short getVerbose();
143
150
156 int getSpeed();
157
158private:
159 friend class packet;
160 friend void * expire_check(void *);
161
167 void receive(bufferStore buf);
168 void transmit(bufferStore buf);
169 void sendAck(int seq);
170 void sendReqReq();
171 void sendReqCon();
172 void sendReq();
173 void multiAck(struct timeval);
174 void retransmit();
175 void transmitHoldQueue(int channel);
176 void transmitWaitQueue();
177 void purgeAllQueues();
178 unsigned long retransTimeout();
179
180 pthread_t checkthread;
181 pthread_mutex_t queueMutex;
182
189 unsigned long conMagic;
190 unsigned short verbose;
191 bool failed;
193
194 std::vector<ackWaitQueueElement> ackWaitQueue;
195 std::vector<bufferStore> holdQueue;
196 std::vector<bufferStore> waitQueue;
197 bool xoff[256];
198};
199
200#endif
Wrapper class featuring range-checking and string representation of enumerated values.
Definition: Enum.h:136
Definition: ncp.h:54
A generic container for an array of bytes.
Definition: bufferstore.h:37
Definition: packet.h:38
Describes a transmitted packet which has not yet been acknowledged by the peer.
Definition: link.h:40
int seq
Original sequence number.
Definition: link.h:44
bufferStore data
Packet content.
Definition: link.h:56
int txcount
Number of remaining transmit retries.
Definition: link.h:48