-
Notifications
You must be signed in to change notification settings - Fork 8
/
io.c
1433 lines (1302 loc) · 39.8 KB
/
io.c
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* IO.C V3.3-mea
| Copyright (c) 1988,1989,1990 by
| The Hebrew University of Jerusalem, Computation Center.
|
| This software is distributed under a license from the Hebrew University
| of Jerusalem. It may be copied only under the terms listed in the license
| agreement. This copyright message should never be changed or removed.
| This software is gievn without any warranty, and the Hebrew University
| of Jerusalem assumes no responsibility for any damage that might be caused
| by use or misuse of this software.
|
| Do the OS independent IO parts.
| Note: The way of saving the last tramitted buffer should be improved. It
| currently saves all data if it is not a NAK. This should be modified
| according to the status, and also the routine that handles the NAK
| should be corrected accordingly.
|
| When a buffer is sent, we send the saved buffer in IoLines structure. This
| is because the buffer we usually get is a dynamic memory location. Thus,
| the XmitBuffer in IoLines structure is the only one which is static.
|
|
| Sections: SHOW-LINES: Send to users the lines status.
| INIT-IO: Initialize the I/O lines.
| QUEUE-IO: Queue an I/O request.
| STATS: Write statistics.
| COMMAND-PARSER Parses the opareator's commands.
*/
#include "consts.h"
#include "headers.h"
#include "prototypes.h"
#ifdef USE_XMIT_QUEUE
void queue_timer_reset(int expiration, int Index, TimerType WhatToDo);
#endif
static int add_VMnet_block __(( struct LINE *Line, const int flag, const void *buffer, const int size, void *NewLine, const int BCBcount ));
static void debug_dump_buffers __(( const char *UserName ));
EXTERNAL int MustShutDown;
EXTERNAL int PassiveSocketChannel;
EXTERNAL int LogLevel;
#define VMNET_INITIAL_TIMEOUT 15 /* 15 seconds */
/*============================ SHOW-LINES ==============================*/
char *StreamStateStr(state)
StreamStates state;
{
switch (state) {
case S_INACTIVE:
return "S_INACTIVE";
case S_REFUSED:
return "S_REFUSED";
case S_WAIT_A_BIT:
return "S_WAIT_A_BIT";
case S_WILL_SEND:
return "S_WILL_SEND";
case S_NJH_SENT:
return "S_NJH_SENT";
case S_NDH_SENT:
return "S_NDH_SENT";
case S_SENDING_FILE:
return "S_SENDING_FILE";
case S_RECEIVING_FILE:
return "S_RECVING_FILE";
case S_NJT_SENT:
return "S_NJT_SENT";
case S_EOF_SENT:
return "S_EOF_SENT";
case S_EOF_FOUND:
return "S_EOF_FOUND";
case S_REQUEST_SENT:
return "S_REQUEST_SENT";
default:
return "**UnknownStreamState**";
}
/* NOTREACHED */
}
static char *linestate2string(state,sockpend)
int state, sockpend;
{
static char bugbuf[10];
switch (state) {
case INACTIVE:
return "INACTIVE ";
case SIGNOFF:
return "SIGNEDOFF ";
case DRAIN:
return "DRAINED ";
case ACTIVE:
return "ACTIVE ";
case F_SIGNON_SENT:
case I_SIGNON_SENT:
return "SGN-Sent ";
case LISTEN:
return "LISTEN ";
case RETRYING:
return "Retry ";
case TCP_SYNC:
if (sockpend >= 0)
return "TCP-pend ";
else
return "TCP-sync ";
default:
sprintf(bugbuf,"**Unk:%d**",(int)state);
return bugbuf;
}
}
static char *linetypedev2string(type,device)
int type;
char *device;
{
static char line[60];
switch (type) {
case DMF:
sprintf(line, " DMF (%s)", device);
return line;
case DMB:
sprintf(line, " DMB (%s)", device);
return line;
break;
case DSV:
sprintf(line, " DSV (%s)", device);
return line;
break;
case UNIX_TCP:
return " TCP ";
case EXOS_TCP:
return " TCP(Exos)";
case MNET_TCP:
return " TCP(Mnet)";
case DEC__TCP:
return " TCP(DEC) ";
case DECNET:
sprintf(line, " DECNET (%s)", device);
return line;
case ASYNC:
sprintf(line, " ASYNC (%s)", device);
return line;
default:
return " ***";
}
}
/*
| Send the lines status to the user.
*/
void show_lines_status(to,infoprint)
const char *to; /* User@Node */
int infoprint;
{
int i, j;
char line[LINESIZE],
from[SHORTLINE]; /* The message's sender address */
struct LINE *Line;
TIMETYPE now;
GETTIME(&now);
/* Create the sender's address.
It is the daemon on the local machine */
sprintf(from, "@%s", LOCAL_NAME); /* No username */
sprintf(line, "FUNET-NJE version %s(%s)/%s, Lines status:",
VERSION, SERIAL_NUMBER, version_time);
send_nmr(from, to, line, strlen(line), ASCII, CMD_MSG);
for (i = 0; i < MAX_LINES; i++) {
Line = &(IoLines[i]);
if (*(Line->HostName) == 0) continue; /* No host defined for this
line, ignore */
sprintf(line, "Line.%d %-8s %3d (Q=%04d) ", i,
Line->HostName, Line->TotalErrors,
Line->QueuedFiles);
strcat(line,linestate2string(Line->state,Line->socketpending));
strcat(line,linetypedev2string(Line->type,Line->device));
send_nmr(from, to, line, strlen(line), ASCII, CMD_MSG);
if (infoprint) {
char InAge[20], XmitAge[20];
char *sep = "", *sepp="|";
TIMETYPE nw;
memcpy(&nw,&now,sizeof(nw));
strcpy(InAge,MsecAgeStr(&Line->InAge,&nw));
memcpy(&nw,&now,sizeof(nw));
if (GETTIMESEC(Line->XmitAge) != 0)
strcpy(XmitAge,MsecAgeStr(&Line->XmitAge,&nw));
else
strcpy(XmitAge,"Never");
sprintf(line," Bufinfo: InAge=%ss, RecvSize=%d, XmitAge=%ss, XmitSize=%d",
InAge, Line->RecvSize, XmitAge, Line->XmitSize);
send_nmr(from, to, line, strlen(line), ASCII, CMD_MSG);
sep=""; strcpy(line," Flags: ");
#define FLGP(flg,str) \
if (Line->flags & flg) { strcat(line,sep);strcat(line,str);sep=sepp; }
FLGP(F_ACK_NULLS, "ACK_NULLS");
FLGP(F_AUTO_RESTART, "AUTO_RESTART");
FLGP(F_CALL_ACK, "CALL_ACK");
FLGP(F_DONT_ACK, "DONT_ACK");
FLGP(F_FAST_OPEN, "FAST_OPEN");
FLGP(F_HALF_DUPLEX, "HALF_DUPLEX");
FLGP(F_IN_SUSPEND, "IN_SUSPEND");
FLGP(F_RELIABLE, "RELIABLE");
FLGP(F_RESET_BCB, "RESET_BCB");
FLGP(F_SENDING, "SENDING");
FLGP(F_SHUT_PENDING, "SHUT_PENDING");
FLGP(F_SLOW_INTERLEAVE, "SLOW_ILEAVE");
FLGP(F_SUSPEND_ALLOWED, "SUSPEND_ALLOWED");
FLGP(F_WAIT_A_BIT, "WAIT_A_BIT");
FLGP(F_WAIT_V_A_BIT, "WAIT_V_A_BIT");
FLGP(F_XMIT_CAN_WAIT, "XMIT_CAN_WAIT");
FLGP(F_XMIT_MORE, "XMIT_MORE");
FLGP(F_XMIT_QUEUE, "XMIT_QUEUE");
#undef FLGP
send_nmr(from, to, line, strlen(line), ASCII, CMD_MSG);
}
if (Line->state != ACTIVE) /* Not active - don't display */
continue; /* streams status */
for (j = 0; j < MAX_STREAMS; j++) {
sprintf(line, "Rcv-%d ", j);
if (Line->InStreamState[j] != S_INACTIVE) {
/* Don't show inactive ones */
switch (Line->InStreamState[j]) {
case S_INACTIVE:
strcat(line, "Inactive");
break;
case S_REQUEST_SENT:
strcat(line, "REQUEST ");
break;
case S_NJH_SENT:
strcat(line, "NJH-RECV");
break;
case S_NDH_SENT:
strcat(line, "NDH-RECV");
break;
case S_NJT_SENT:
strcat(line, "NJT-RECV");
break;
case S_RECEIVING_FILE:
strcat(line, "RECVING ");
break;
case S_EOF_SENT:
strcat(line, "EOF-RECV");
break;
case S_REFUSED:
strcat(line, "REFUSED ");
break;
case S_WAIT_A_BIT:
strcat(line, "WAITABIT");
break;
default:
strcat(line, "****** ");
break;
}
if ((Line->InStreamState[j] != S_INACTIVE) &&
(Line->InStreamState[j] != S_REFUSED) )
sprintf(line+strlen(line), " (%s) (%s => %s) %dkB",
Line->InFileParams[j].JobName,
Line->InFileParams[j].From,
Line->InFileParams[j].To,
(int)(Line->OutFilePos[j]/1024));
send_nmr(from, to, line, strlen(line), ASCII, CMD_MSG);
}
sprintf(line, "Snd-%d ", j);
if (Line->OutStreamState[j] != S_INACTIVE) {
/* Don't show inactive ones */
switch(Line->OutStreamState[j]) {
case S_INACTIVE:
strcat(line, "Inactive");
break;
case S_REQUEST_SENT:
strcat(line, "REQUEST ");
break;
case S_NJH_SENT:
strcat(line, "NJH-SENT");
break;
case S_NDH_SENT:
strcat(line, "NDH-SENT");
break;
case S_SENDING_FILE:
strcat(line, "SENDING ");
break;
case S_NJT_SENT:
strcat(line, "NJT-SENT");
break;
case S_EOF_SENT:
strcat(line, "EOF-SENT");
break;
case S_REFUSED:
strcat(line, "REFUSED ");
break;
case S_WAIT_A_BIT:
strcat(line, "WAITABIT");
break;
default:
strcat(line, "****** ");
break;
}
if ((Line->OutStreamState[j] != S_INACTIVE) &&
(Line->OutStreamState[j] != S_REFUSED) )
sprintf(line+strlen(line), " (%s) (%s => %s) %dkB",
Line->OutFileParams[j].JobName,
Line->OutFileParams[j].From,
Line->OutFileParams[j].To,
(int)(Line->InFilePos[j]/1024));
send_nmr(from, to, line, strlen(line), ASCII, CMD_MSG);
}
}
sprintf(line,
" %d streams in service. WrSum: %ldfil/%ldB RdSum: %ldfil/%ldB",
Line->MaxStreams,
Line->WrFiles, Line->WrBytes, Line->RdFiles, Line->RdBytes);
send_nmr(from, to, line, strlen(line), ASCII, CMD_MSG);
}
sprintf(line, "End of Q SYS display");
send_nmr(from, to, line, strlen(line), ASCII, CMD_MSG);
}
/*
| Send the lines statistics to the user.
*/
void
show_lines_stats(to)
const char *to; /* User@Node */
{
int i;
char line[LINESIZE],
from[SHORTLINE]; /* The message's sender address */
struct LINE *Line;
/* Create the sender's address. It is the daemon on the local machine */
sprintf(from, "@%s", LOCAL_NAME); /* No username */
sprintf(line, "FUNET-NJE version %s(%s)/%s, Lines statistics:",
VERSION, SERIAL_NUMBER, version_time);
send_nmr(from, to, line, strlen(line), ASCII, CMD_MSG);
for (i = 0; i < MAX_LINES; i++) {
Line = &(IoLines[i]);
if (*(Line->HostName) != '\0') {
sprintf(line, "Line.%d %8s: Blocks send/recv: %d/%d, Wait recvd: %d,",
i, Line->HostName,
Line->sumstats.TotalOut+Line->stats.TotalOut,
Line->sumstats.TotalIn+Line->stats.TotalIn,
Line->sumstats.WaitIn+Line->stats.WaitIn );
send_nmr(from, to, line, strlen(line), ASCII, CMD_MSG);
sprintf(line, " NMRs sent/recv: %d/%d, NAKs send/recvd: %d/%d, Acks-only sent/recv: %d/%d",
Line->sumstats.MessagesOut+Line->stats.MessagesOut,
Line->sumstats.MessagesIn+Line->stats.MessagesIn,
Line->sumstats.RetriesOut+Line->stats.RetriesOut,
Line->sumstats.RetriesIn+Line->stats.RetriesIn,
Line->sumstats.AckOut+Line->stats.AckOut,
Line->sumstats.AckIn+Line->stats.AckIn);
send_nmr(from, to, line, strlen(line), ASCII, CMD_MSG);
}
}
sprintf(line, "End of Q STAT display");
send_nmr(from, to, line, strlen(line), ASCII, CMD_MSG);
}
/*======================= INIT-IO ==================================*/
/*
| Initialize all the communication lines. Initialize DMFs, TCP and
| DECnet connections, each one only if there is a link of that type.
| If we have at least one TCP passive end, we don't queue an accept for
| the specific line. We queue only one accept, regarding of the number of
| passive ends. When a connection will be received, the VMnet control record
| will be used to locate the correct line.
*/
void
init_communication_lines()
{
int i, InitTcpPassive, InitDECnetPassive = 0, TcpType = 0;
InitDECnetPassive = InitTcpPassive = 0;
for (i = 0; i < MAX_LINES; i++) {
if (IoLines[i].HostName[0] == 0) continue; /* no line */
if (IoLines[i].state == ACTIVE) {
switch (IoLines[i].type) {
#ifdef VMS
case DMB:
case DSV:
case DMF:
init_dmf_connection(i);
queue_receive(i);
break;
case DEC__TCP:
case MNET_TCP:
case EXOS_TCP:
/* Create an active side and also passive side */
init_active_tcp_connection(i,0);
InitTcpPassive++;
TcpType = IoLines[i].type;
break;
case ASYNC:
init_async_connection(i);
queue_receive(i);
break;
case DECNET:
init_active_DECnet_connection(i);
InitDECnetPassive++;
break;
#endif
#ifdef UNIX
case UNIX_TCP:
init_active_tcp_connection(i,0);
InitTcpPassive++;
break;
#endif
case X_25:
default:
logger(1, "IO: No protocol for line #%d\n",
i);
break;
}
}
}
/* Check whether we have to queue a passive accept for TCP & DECnet lines */
if(InitTcpPassive != 0)
init_passive_tcp_connection(TcpType);
#ifdef VMS
if (InitDECnetPassive != 0)
init_DECnet_passive_channel();
#endif
}
void
abort_streams_and_requeue(Index)
int Index;
{
int i;
struct LINE *Line = &IoLines[Index];
struct MESSAGE *MessageEntry;
logger(2, "IO: init_link_state(%s/%d) type=%d (Q=%d)\n",
Line->HostName, Index, Line->type, Line->QueuedFiles);
/* Close active file, and delete of output file. */
for (i = 0; i < MAX_STREAMS; i++) {
Line->CurrentStream = i;
if ((Line->OutStreamState[i] != S_INACTIVE) &&
(Line->OutStreamState[i] != S_REFUSED)) { /* File active */
close_file(Index, F_INPUT_FILE, i);
Line->OutStreamState[i] = S_INACTIVE;
requeue_file_entry(Index,Line);
}
if ((Line->InStreamState[i] != S_INACTIVE) &&
(Line->InStreamState[i] != S_REFUSED)) { /* File active */
delete_file(Index, F_OUTPUT_FILE, i);
Line->InStreamState[i] = S_INACTIVE;
}
}
i = requeue_file_queue(Line);
if (i != 0)
logger(1,"IO: init_link_state() calling requeue_file_queue() got an activecount of %d! Should be 0!\n",i);
/* Line->QueuedFiles = i; */
/* Line->QueuedFilesWaiting = 0; */
/* Requeue all messages and commands waiting on it */
MessageEntry = Line->MessageQstart;
Line->MessageQstart = NULL;
Line->MessageQend = NULL;
while (MessageEntry != NULL) {
struct MESSAGE *NextEntry = MessageEntry->next;
nmr_queue_msg(MessageEntry);
free(MessageEntry);
MessageEntry = NextEntry;
}
}
/*
| Reset various link state variables, make sure all open files
| get closed, queue states get reset, etc..
*/
void
init_link_state(Index)
const int Index;
{
struct LINE *Line;
register int i; /* Stream index */
int oldstate;
Line = &(IoLines[Index]);
if (Index > MAX_LINES || Line->HostName[0] == 0) {
logger(1,"IO: init_link_state(%d) - Bad line number!\n",Index);
return;
}
if (Line->socket >= 0)
close(Line->socket);
Line->socket = -1;
if (Line->socketpending >= 0)
close(Line->socketpending);
Line->socketpending = -1;
#ifdef NBSTREAM
Line->WritePending = NULL;
#endif
oldstate = Line->state;
Line->state = INACTIVE;
abort_streams_and_requeue(Index);
Line->state = oldstate;
#ifdef USE_XMIT_QUEUE
/* Clear all queued transmit buffers */
while (Line->FirstXmitEntry != Line->LastXmitEntry) {
if (Line->XmitQueue[Line->FirstXmitEntry])
free(Line->XmitQueue[Line->FirstXmitEntry]);
Line->XmitQueue[Line->FirstXmitEntry] = NULL;
Line->FirstXmitEntry = (Line->FirstXmitEntry +1) % MAX_XMIT_QUEUE;
}
Line->FirstXmitEntry = 0;
Line->LastXmitEntry = 0;
#endif
/* After all files closed, restart the line */
Line->errors = 0; /* We start again... */
Line->InBCB = 0;
/* Line->OutBCB = 0; */
Line->flags &= ~(F_RESET_BCB |
F_WAIT_A_BIT | F_WAIT_V_A_BIT |
F_SENDING | F_CALL_ACK |
F_XMIT_CAN_WAIT| F_SLOW_INTERLEAVE);
Line->CurrentStream = 0;
Line->ActiveStreams = 0;
Line->FreeStreams = Line->MaxStreams;
for (i = 0; i < MAX_STREAMS; i++) {
Line->InStreamState[i] = S_INACTIVE;
Line->OutStreamState[i] = S_INACTIVE;
}
Line->RecvSize = 0;
Line->XmitSize = 0;
Line->WritePending = NULL;
/* Dequeue all waiting timeouts for this line */
delete_line_timeouts(Index);
}
/*
| Restart a line that is not active.
*/
void
restart_line(Index)
const int Index;
{
struct LINE *Line = &IoLines[Index];
/* First check the line is in correct status */
if ((Index < 0) || (Index >= MAX_LINES)) {
logger(1, "IO, Restart line: line #%d out of range\n",
Index);
return;
}
Line->flags &= ~F_SHUT_PENDING; /* Remove the shutdown pending flag. */
switch (Line->state) {
case INACTIVE:
case SIGNOFF:
case RETRYING:
break; /* OK - go ahead and start it */
case DRAIN:
case F_SIGNON_SENT:
case I_SIGNON_SENT:
logger(1, "IO, Trying to start line %s (#%d) in state %d. Illegal\n",
Line->HostName, Index, Line->state);
return;
default:
logger(1, "IO, Line %s (#%d) in illegal state (#%d) for start op.\n",
Line->HostName,Index,Line->state);
return;
}
logger(2, "IO, Restarting line #%d (%s) (Q=%d)\n",
Index, Line->HostName, Line->QueuedFiles);
/* Init the line according to its type */
Line->state = DRAIN; /* Will be set to INACTIVE in case
of error during initialization. */
/* Programmable backoff.. */
if (Line->RetryIndex < MAX_RETRIES-1 &&
Line->RetryPeriods[Line->RetryIndex+1] > 0)
Line->RetryPeriod = Line->RetryPeriods[Line->RetryIndex++];
else
Line->RetryPeriod = Line->RetryPeriods[Line->RetryIndex];
init_link_state(Index);
switch (Line->type) {
#ifdef VMS
case DMB:
case DSV:
case DMF:
init_dmf_connection(Index);
queue_receive(Index);
break;
case DEC__TCP:
case MNET_TCP:
case EXOS_TCP:
init_active_tcp_connection(Index,0);
break;
case DECNET:
init_active_DECnet_connection(Index);
break;
case ASYNC:
init_async_connection(Index);
queue_receive(Index);
break;
#endif
#ifdef UNIX
case UNIX_TCP:
init_active_tcp_connection(Index,0);
break;
#endif
default:
break;
}
}
/*===================== QUEUE-IO =====================================*/
/*
| Queue the receive for the given line. Test its type, and then call the
| appropriate routine. Also queue a timer request for it (our internal
| timer, not the VMS one).
*/
void
queue_receive(Index)
const int Index;
{
struct LINE *Line;
Line = &(IoLines[Index]);
/* Do we have to queue a receive ??? */
switch (Line->state) {
case INACTIVE:
case SIGNOFF:
case RETRYING:
case LISTEN: /* No need to requeue on these states */
return;
case ACTIVE:
case DRAIN:
case F_SIGNON_SENT:
case I_SIGNON_SENT:
case TCP_SYNC:
break; /* OK, requeue it */
default:
logger(1, "IO, Illegal line state %d on line %d during queue-Receive\n",
Line->state, Index);
Line->state = INACTIVE;
return;
}
switch (Line->type) {
#ifdef VMS
case DMB:
case DSV:
case DMF:
if (queue_dmf_receive(Index) != 0)
/* Queue a timeout for it */
Line->TimerIndex =
queue_timer(Line->TimeOut, Index, T_DMF_CLEAN);
break;
case ASYNC:
if (queue_async_receive(Index) != 0)
Line->TimerIndex =
queue_timer(Line->TimeOut, Index, T_ASYNC_TIMEOUT);
break;
case DECNET:
if (queue_DECnet_receive(Index) != 0)
Line->TimerIndex =
queue_timer(Line->TimeOut, Index,
T_DECNET_TIMEOUT);
break;
#ifdef EXOS
case EXOS_TCP:
if (queue_exos_tcp_receive(Index) != 0) {
if (Line->state != ACTIVE)
Line->TimerIndex =
queue_timer(VMNET_INITIAL_TIMEOUT,
Index, T_TCP_TIMEOUT);
else
Line->TimerIndex =
queue_timer(Line->TimeOut, Index,
T_TCP_TIMEOUT);
}
break;
#endif
#ifdef MULTINET_or_DEC
case DEC__TCP:
case MNET_TCP:
if (queue_mnet_tcp_receive(Index) != 0)
/* If the link was not established yet, use longer timeout
(since the VMnet is running here in a locked-step mode
on the VM side). If we use the regular small timeout we
make the login process difficult (we transmit the next
DLE-ENQ packet while the other side is acking the previous
one. This is caused due to slow lines). */
if (Line->state != ACTIVE)
Line->TimerIndex =
queue_timer(VMNET_INITIAL_TIMEOUT,
Index, T_TCP_TIMEOUT);
else
Line->TimerIndex =
queue_timer(Line->TimeOut, Index,
T_TCP_TIMEOUT);
break;
#endif
#endif /* VMS */
#ifdef UNIX
case UNIX_TCP: /* We poll here, so we don't queue a real receive */
Line->TimerIndex =
queue_timer(Line->TimeOut, Index, T_TCP_TIMEOUT);
break;
#endif /* UNIX */
default:
logger(1, "IO: No support for device on line #%d\n", Index);
break;
}
}
/*
| Send the data using the correct interface. Before sending, add BCB+FCS and
| CRC if asked for.
| If the line is of TCP or DECnet type, we add only the first headers, and
| do not add the tralier (DLE+ETB_CRCs) and we do not duplicate DLE's.
| See comments about buffers at the head of this module.
| If we are called when the link is already transmitting (and haven't finished
| it), then the buffer is queued for later transmission if the line supports
| it. The write AST routine will send it.
*/
void
send_data(Index, buffer, size, AddEnvelope)
const int Index, size, AddEnvelope; /* Add the BCB+...? */
const void *buffer;
{
struct LINE *Line;
int NewSize;
const unsigned char *SendBuffer;
register int i, flag;
/* In the followings, ttr/b is used to point inside the buffer, while
Ttr/b is used to construct the buffer (RISC alignment..). */
char *ttb, *ttr;
struct TTB Ttb;
struct TTR Ttr;
#ifdef USE_XMIT_QUEUE
unsigned char *p;
register int NextEntry;
#endif
Line = &(IoLines[Index]);
Line->flags &= ~F_XMIT_MORE; /* Default - do not block */
/* Collects stats */
if (*(unsigned char *)buffer != NAK)
Line->stats.TotalOut++;
else
Line->stats.RetriesOut++;
SendBuffer = buffer;
NewSize = size;
i = Line->OutBCB;
flag = (Line->flags & F_RESET_BCB);
/* if (flag)
logger(1,"IO: send_data(), F_RESET_BCB, line=%s\n",Line->HostName); */
#ifdef USE_XMIT_QUEUE
/* Test whether the link is already transmitting.
If so, queue the message only if the link supports so.
If not, ignore this transmission. */
if (
#ifdef NBSTREAM
Line->WritePending != NULL ||
#endif
Line->LastXmitEntry != Line->FirstXmitEntry || /* Something in queue */
(Line->flags & F_SENDING) != 0) { /* Yes - it is occupied */
if ((Line->flags & F_RELIABLE) == 0) {
logger(1, "IO: Line %s doesn't support queueing\n",
Line->HostName);
return; /* Ignore it */
}
Line->flags |= F_WAIT_V_A_BIT; /* Signal wait-a-bit so sender
will not transmit more */
/* Calculate where shall we put it in the queue (Cyclic queue) */
NextEntry = (Line->LastXmitEntry + 1) % MAX_XMIT_QUEUE;
/* If the new last is the same as the first one,
then we have no place... */
if (NextEntry == Line->FirstXmitEntry) {
int canwait = (Line->flags & F_XMIT_CAN_WAIT);
logger(1, "IO: No place to queue Xmit on line %s:%d can%s wait ABORTING\n",
Line->HostName,Line->CurrentStream, canwait ? "":"'t" );
Line->flags |= F_CALL_ACK;
bug_check("IO: Overflowed XMIT_QUEUE");
return;
}
/* There is a place - queue it */
if ((p = (unsigned char*)malloc(size + TTB_SIZE + 5 + 2 +
/* 5 for BCB+FCS overhead,
2 for DECnet CRC */
2 * TTR_SIZE)) == NULL) {
#ifdef VMS
logger(1, "IO, Can't malloc. Errno=%d, VaxErrno=%d\n",
errno, vaxc$errno);
#else
logger(1, "IO, Can't malloc. Errno=%d\n", errno);
#endif
bug_check("IO, Can't malloc() memory\n");
}
NewSize = add_VMnet_block(Line, AddEnvelope,
buffer, size, p + TTB_SIZE, i);
SendBuffer = p;
if (AddEnvelope == ADD_BCB_CRC)
if (flag != 0) /* If we had to reset BCB, don't increment */
Line->OutBCB = (i + 1) % 16;
/* <TTB>(LN=length_of_VMnet+TTR) <VMnet_block> <TTR>(LN=0) */
Ttr.F = Ttr.U = 0;
Ttr.LN = 0; /* Last TTR */
ttr = (void *)(p + NewSize + TTB_SIZE);
memcpy(ttr, &Ttr, TTR_SIZE);
NewSize += (TTB_SIZE + TTR_SIZE);
Ttb.F = 0; /* No flags */
Ttb.U = 0;
Ttb.LN = htons(NewSize);
Ttb.UnUsed = 0;
ttb = (void *)(p + 0);
memcpy(ttb, &Ttb, TTB_SIZE);
Line->XmitQueue[Line->LastXmitEntry] = (char *)p;
Line->XmitQueueSize[Line->LastXmitEntry] = NewSize;
Line->LastXmitEntry = NextEntry;
/* Put a timer there waiting for us.. */
/* logger(2,"IO: XMIT-Queued %d bytes to line %s\n",NewSize,Line->HostName); */
queue_timer_reset(T_XMIT_INTERVAL, Index, T_XMIT_DEQUEUE);
Line->flags |= F_CALL_ACK;
return;
}
#endif
/* No queueing - format buffer into output buffer.
If the line is TCP - block more records if can.
Other types - don't try to block. */
if ((Line->flags & F_RELIABLE) != 0) {
/* There are DECNET, or TCP/IP links, which get TTB + TTRs */
if (Line->XmitSize == 0)
Line->XmitSize = TTB_SIZE;
/* First block - leave space for TTB */
NewSize = add_VMnet_block(Line, AddEnvelope, buffer, size,
Line->XmitBuffer + Line->XmitSize, i);
Line->XmitSize += NewSize;
if (AddEnvelope == ADD_BCB_CRC)
if (flag != 0) /* If we had to reset BCB, don't increment */
Line->OutBCB = (i + 1) % 16;
} else { /* Normal block */
if (AddEnvelope == ADD_BCB_CRC) {
if ((Line->type == DMB) || (Line->type == DSV))
Line->XmitSize =
NewSize = add_bcb(Index, buffer,
size, Line->XmitBuffer, i);
else
Line->XmitSize =
NewSize = add_bcb_crc(Index, buffer,
size, Line->XmitBuffer, i);
if (flag != 0) /* If we had to reset BCB, don't increment */
Line->OutBCB = (i + 1) % 16;
} else {
memcpy(Line->XmitBuffer, buffer, size);
Line->XmitSize = size;
}
SendBuffer = Line->XmitBuffer;
}
/* Check whether we've overflowed some buffer. If so - bugcheck... */
if (Line->XmitSize > MAX_BUF_SIZE) {
logger(1, "IO: Xmit buffer overflow in line #%d\n", Index);
bug_check("Xmit buffer overflow\n");
}
/* If TcpIp line and there is room in buffer and the sender
allows us to defer sending - return. */
if ((Line->flags & F_RELIABLE) != 0) {
if ((Line->flags & F_XMIT_CAN_WAIT) != 0 &&
(Line->XmitSize + TTB_SIZE +
2 * TTR_SIZE + 5 + 2 +
/* +5 for BCB + FCS overhead, +2 for DECnet;s CRC */
Line->MaxXmitSize) < Line->TcpXmitSize) { /* There is room */
Line->flags |= (F_XMIT_MORE | F_CALL_ACK);
return;
}
/* Ok - we have to transmit buffer. If DECnet or TcpIp - insert
the TTB and add TTR at end */
NewSize = Line->XmitSize;
ttb = (void *)Line->XmitBuffer;
ttr = (void *)(Line->XmitBuffer + NewSize);
Ttr.F = Ttr.U = 0;
Ttr.LN = 0; /* Last TTR */
memcpy(ttr, &Ttr, TTR_SIZE);
Line->XmitSize = NewSize = NewSize + TTR_SIZE;
Ttb.F = 0; /* No flags */
Ttb.U = 0;
Ttb.LN = htons(NewSize);
Ttb.UnUsed = 0;
memcpy(ttb, &Ttb, TTB_SIZE);
SendBuffer = Line->XmitBuffer;
/* Check whether we've overflowed some buffer. If so - bugcheck... */
if (Line->XmitSize > MAX_BUF_SIZE) {
logger(1, "IO, TCP Xmit buffer overflow in line #%d\n", Index);
bug_check("Xmit buffer overflow\n");
}
}
Line = &(IoLines[Index]);
#ifdef DEBUG
logger(3, "IO: Sending: line=%s, size=%d, sequence=%d:\n",
Line->HostName, NewSize, i);
trace(SendBuffer, NewSize, 5);
#endif
switch(Line->type) {
#ifdef VMS
case ASYNC:
send_async(Index, SendBuffer, NewSize);
return;
case DMB:
case DSV:
case DMF:
send_dmf(Index, SendBuffer, NewSize);
return;
case DECNET:
send_DECnet(Index, SendBuffer, NewSize);
return;
#ifdef EXOS
case EXOS_TCP:
send_exos_tcp(Index, SendBuffer, NewSize);
return;
#endif
#ifdef MULTINET_or_DEC
case DEC__TCP:
case MNET_TCP:
send_mnet_tcp(Index, SendBuffer, NewSize);
return;
#endif
#endif
#ifdef UNIX
case UNIX_TCP:
send_unix_tcp(Index, SendBuffer, NewSize);
return;
#endif
default:
logger(1, "IO: No support for device on line #%d\n", Index);
break;
}
}