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#pragma once
22
23#include "config.h"
24#include <pthread.h>
25#include <sys/time.h>
26
27#include "bufferstore.h"
28#include "bufferarray.h"
29#include "Enum.h"
30#include <vector>
31
32class DataLink;
33class NCP;
34
39typedef struct {
43 int seq;
51 struct timeval stamp;
57
58extern "C" {
59 static void *expire_check(void *);
60}
61
62class Link {
63public:
64
65 enum link_type {
69 };
70
81 Link(const char *fname, int baud, NCP *ncp, bool noDSRCheck, 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
122 void purgeQueue(int channel);
123
130
136 int getSpeed();
137
138private:
139 friend class DataLink;
140 friend void * expire_check(void *);
141
147 void receive(BufferStore buf);
148 void transmit(BufferStore buf);
149 void sendAck(int seq, Enum<link_type> linkType);
150 void sendReqReq();
151 void sendReqCon();
152 void sendReq(Enum<link_type> linkType);
153 void multiAck(struct timeval);
154 void retransmit();
155 void transmitHoldQueue(int channel);
156 void transmitWaitQueue();
157 void purgeAllQueues();
158 unsigned long retransTimeout();
159
160 pthread_t checkThreadId_;
161 pthread_mutex_t queueMutex_;
162
163 NCP * const ncp_;
164 DataLink *dataLink_ = nullptr;
165 int txSequence_ = 1;
166 int rxSequence_ = -1;
167 int seqMask_ = 7;
169 unsigned long conMagic_;
170 const unsigned short verbose_;
173
174 std::vector<AckWaitQueueElement> ackWaitQueue;
175 std::vector<BufferStore> holdQueue_;
176 std::vector<BufferStore> waitQueue_;
177 bool xoff_[256];
178
185};
A generic container for an array of bytes.
Definition: bufferstore.h:36
Wrapper class featuring range-checking and string representation of enumerated values.
Definition: Enum.h:135
Definition: ncp.h:55
int verbose
Definition: plpprintd.cc:58
Describes a transmitted packet which has not yet been acknowledged by the peer.
Definition: link.h:39
BufferStore data
Packet content.
Definition: link.h:55
int txcount
Number of remaining transmit retries.
Definition: link.h:47
int seq
Original sequence number.
Definition: link.h:43