-
Notifications
You must be signed in to change notification settings - Fork 0
/
outstr.cc
83 lines (75 loc) · 1.84 KB
/
outstr.cc
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
76
77
78
79
80
81
82
83
// -*- C++ -*-
//
// OutputStream class implementation.
//
// Copyright 1992-2021 Deven T. Corzine <[email protected]>
//
// SPDX-License-Identifier: MIT
//
#include "phoenix.h"
void OutputStreamObject::output(Telnet *telnet)
{ // Output object.
if (!Output) return;
Output->output(telnet);
telnet->TimingMark();
}
void OutputStream::Attach(Telnet *telnet) // Review detached output.
{
sent = NULL;
Acknowledged = Sent = 0;
if (telnet && telnet->acknowledge) while (SendNext(telnet)) ;
}
// Enqueue output.
void OutputStream::Enqueue(Telnet *telnet, OutputObj *out)
{
if (!out) return;
if (tail) {
tail->next = new OutputStreamObject(out);
tail = tail->next;
} else {
head = tail = new OutputStreamObject(out);
}
if (!telnet) return;
if (telnet->acknowledge) {
while (SendNext(telnet)) ;
} else {
if (!telnet->Output.head) SendNext(telnet);
}
}
void OutputStream::Unenqueue(OutputObj *out)
{
if (!out) return;
for (OutputStreamObject *node = head; node; node = node->next) {
if (node->Output == out) node->Output = NULL;
}
}
void OutputStream::Dequeue() // Dequeue all acknowledged output.
{
OutputStreamObject *out;
if (Acknowledged) {
while (Acknowledged && Sent && (out = head)) {
Acknowledged--;
Sent--;
head = out->next;
delete out;
}
if (!head) {
sent = tail = NULL;
Acknowledged = Sent = 0;
}
}
}
boolean OutputStream::SendNext(Telnet *telnet) // Send next output.
{
if (!telnet || (!sent && !head)) return false;
if (sent && !sent->next) {
telnet->RedrawInput();
return false;
} else {
sent = sent ? sent->next : head;
telnet->UndrawInput();
sent->output(telnet);
Sent++;
}
return true;
}