This repository has been archived by the owner on Apr 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
ftp_eb.c
826 lines (698 loc) · 18.3 KB
/
ftp_eb.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
/*
* University of Illinois/NCSA Open Source License
*
* Copyright © 2003-2012 NCSA. All rights reserved.
*
* Developed by:
*
* Storage Enabling Technologies (SET)
*
* Nation Center for Supercomputing Applications (NCSA)
*
* http://dims.ncsa.uiuc.edu/set/uberftp
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the .Software.),
* to deal with the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* + Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
*
* + Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in the
* documentation and/or other materials provided with the distribution.
*
* + Neither the names of SET, NCSA
* nor the names of its contributors may be used to endorse or promote
* products derived from this Software without specific prior written
* permission.
*
* THE SOFTWARE IS PROVIDED .AS IS., WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS WITH THE SOFTWARE.
*/
/*
* NOTE ABOUT FILE/TRANSFER OFFSETS IN EXTENDED BLOCK MODE
*
* The offset used for sending/receiving buffers in extended block mode
* should be the transfer offset (starting at 0 regardless of starting
* file offset). If the transfer is a restart, the first offset received
* will not be zero but only because it is a restart!
*
* STOR <file> - Offset 0, 1, 2
* ESTO <off> <len> <file> - Offset 0, 1, 2 (receiver should add <off>)
* REST <off1>-<off2> - Offset 0-off1, off2, ...
* REST 0-<off1> - Offset off1, off1+1, ...
*
* This was determined by watching globus-url-copy and globus-gridftp-server
* in GT 5.2.3rc2.
*/
#include <stdlib.h>
#include "settings.h"
#include "errcode.h"
#include "network.h"
#include "output.h"
#include "ftp_eb.h"
#include "misc.h"
#include "gsi.h"
#include "ftp.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif /* DMALLOC */
#define DC_STATE_ACCEPT 0x00
#define DC_STATE_CONNECT 0x01
#define DC_STATE_ACCEPT_AUTH 0x02
#define DC_STATE_CONNECT_AUTH 0x03
#define DC_STATE_HEADER_PULLUP 0x04
#define DC_STATE_READ_READY 0x05
#define DC_STATE_READY 0x10
#define DC_STATE_PUSH_HEADER 0x20
#define DC_STATE_FLUSH_HEADER 0x30
#define DC_STATE_PUSH_DATA 0x40
#define DC_STATE_FLUSH_DATA 0x50
#define DC_STATE_PUSH_EOF 0x60
#define DC_STATE_FLUSH_EOF 0x70
#define DC_STATE_PUSH_EOD 0x80
#define DC_STATE_FLUSH_EOD 0x90
#define DC_STATE_EOD 0xA0
#define EB_HEADER_LEN (1+8+8)
typedef struct _dc_ {
nh_t * nh;
gh_t * gh;
char * buf;
int buflen;
int state; /* 0 read/write, 1 listen, 2 connect */
int eod;
int eof;
globus_off_t off;
globus_off_t count;
} dc_t;
typedef struct {
dc_t * dcs;
int dccnt;
int eods;
int eeods;
} ebpd_t;
static errcode_t
_f_eb_read_pullup(dc_t * dc);
static errcode_t
_f_eb_header_pullup(ebpd_t * ebpd, dc_t * dc);
static errcode_t
_f_eb_poll(dch_t * dch);
static char *
_f_eb_header(char desc, globus_off_t count, globus_off_t off);
static errcode_t
_f_eb_push_header(ebpd_t * ebpd, dc_t * dc);
static errcode_t
_f_eb_push_eod(ebpd_t * ebpd, dc_t * dc);
static errcode_t
_f_eb_push_eof(ebpd_t * ebpd, dc_t * dc);
static errcode_t
_f_eb_push_data(ebpd_t * ebpd, dc_t * dc);
static errcode_t
_f_eb_active(dch_t * dch, struct sockaddr_in * sin, int scnt)
{
errcode_t ec = EC_SUCCESS;
ebpd_t * ebpd = NULL;
int s = 0;
int p = 0;
dch->privdata = ebpd = (ebpd_t*) malloc(sizeof(ebpd_t));
memset(ebpd, 0, sizeof(ebpd_t));
ebpd->dcs = (dc_t*) malloc(sizeof(dc_t) * (scnt * s_parallel()));
memset(ebpd->dcs, 0, sizeof(dc_t) * (scnt * s_parallel()));
for (s = 0; s < scnt; s++)
{
for (p = 0; p < s_parallel(); p++)
{
/* Non blocking connect. */
ec = net_connect(&ebpd->dcs[ebpd->dccnt].nh, &sin[s]);
if (ec)
return ec;
ebpd->dcs[ebpd->dccnt].state = DC_STATE_CONNECT;
ebpd->dccnt++;
}
}
ebpd->eeods = ebpd->dccnt;
return ec;
}
static errcode_t
_f_eb_passive(dch_t * dch, struct sockaddr_in * sin)
{
errcode_t ec = EC_SUCCESS;
ebpd_t * ebpd = NULL;
dch->privdata = ebpd = (ebpd_t*) malloc(sizeof(ebpd_t));
memset(ebpd, 0, sizeof(ebpd_t));
ebpd->dcs = (dc_t*) malloc(sizeof(dc_t));
memset(ebpd->dcs, 0, sizeof(dc_t));
ec = net_listen(&ebpd->dcs[0].nh, sin);
if (ec)
return ec;
ebpd->dcs[0].state = DC_STATE_ACCEPT;
ebpd->dccnt++;
return ec;
}
static errcode_t
_f_eb_read_ready(dch_t * dch, int * ready)
{
int i = 0;
int eods = 0;
ebpd_t * ebpd = (ebpd_t *) dch->privdata;
errcode_t ec = EC_SUCCESS;
/* Initialize the return. */
*ready = 0;
/* 'poll' to push each channel forward. */
ec = _f_eb_poll(dch);
if (ec)
return ec;
/*
* We are 'read ready' if any channel is in READ_READY and has a buflen > 0
* or all channels are at eod w/ count = 0.
*/
for (i = 0; i < ebpd->dccnt; i++)
{
/* If the channel is at eod w/ no data to read... */
if (ebpd->dcs[i].eod && ebpd->dcs[i].count == 0)
eods++;
if (ebpd->dcs[i].state == DC_STATE_READ_READY)
{
if (ebpd->dcs[i].buflen > 0)
{
*ready = 1;
return EC_SUCCESS;
}
}
}
/* If no one was ready... */
if (*ready == 0)
{
/* If we received the EOF header... */
if (ebpd->eeods > 0)
{
/* If every channel has received an EOD... */
if (ebpd->eeods == eods)
*ready = 1;
}
}
return EC_SUCCESS;
}
static errcode_t
_f_eb_read(dch_t * dch,
char ** buf,
globus_off_t * off,
size_t * len,
int * eof)
{
int i = 0;
dc_t * dc = NULL;
ebpd_t * ebpd = (ebpd_t *) dch->privdata;
errcode_t ec = EC_SUCCESS;
*buf = NULL;
*len = 0;
*off = 0;
*eof = 0;
while (!dc)
{
ec = _f_eb_poll(dch);
if (ec)
return ec;
for (i = 0; i < ebpd->dccnt; i++)
{
if (ebpd->dcs[i].state == DC_STATE_READ_READY)
{
/* If this channel is at eod w/ no data to follow... */
if (ebpd->dcs[i].eod && ebpd->dcs[i].count == 0)
{
/* Mark the channel as EOD. */
ebpd->dcs[i].state = DC_STATE_EOD;
/* Increment the eod count. */
ebpd->eods++;
/* Continue to the next channel. */
continue;
}
/* If this channel has data in its buffer... */
if (ebpd->dcs[i].buflen > 0)
{
/* Find the larget buffer to read. */
if (!dc || dc->buflen < ebpd->dcs[i].buflen)
dc = &ebpd->dcs[i];
}
}
}
/* If we could not find a channel to read... */
if (!dc)
{
/* If we have received the EOF header w/ the expected eod count...*/
if (ebpd->eeods > 0)
{
/* If all channels are now at EOD... */
if (ebpd->eods == ebpd->eeods)
{
/* Indicate EOF to the caller. */
*eof = 1;
/* Return success. */
return EC_SUCCESS;
}
}
}
}
/*
* We have a channel w/ a buffer!
*
* 4 scenerios here:
* 1) We have more data than this block holds. Copy it out and pull the
* next header.
* 2) We have less data than this block holds. Copy it out and read more
* data.
* 3) We have all data this block holds and eod. Pull it out and indicate
* EOD.
* 4) We have all data this block holds and !eod. Pull it out and pull
* the next header.
*/
/* If we have more data than this block holds... */
if (dc->buflen > dc->count)
{
/* This would be illegal. */
assert(dc->eod == 0);
/* Copy it out. */
*buf = malloc(dc->count);
*len = dc->count;
*off = dc->off;
memcpy(*buf, dc->buf, dc->count);
memmove(dc->buf, dc->buf + dc->count, dc->buflen - dc->count);
dc->buflen -= dc->count;
dc->off += dc->count;
dc->count = 0;
} else
{
/* Give them the actual buffer. */
*len = dc->buflen;
*buf = dc->buf;
*off = dc->off;
dc->buf = NULL;
dc->count -= dc->buflen;
dc->off += dc->buflen;
dc->buflen = 0;
}
*off += dch->partial_off;
if (dc->eod == 1 && dc->count == 0)
{
/* Mark the channel as EOD. */
dc->state = DC_STATE_EOD;
/* Increment the eod count. */
ebpd->eods++;
/* If we have received the EOF header w/ the expected eod count...*/
if (ebpd->eeods > 0)
{
/* If all channels are now at EOD... */
if (ebpd->eods == ebpd->eeods)
{
/* Indicate EOF to the caller. */
*eof = 1;
}
}
return EC_SUCCESS;
}
/* If the block is done. */
if (dc->count == 0)
{
/* Read the next header. */
dc->state = DC_STATE_HEADER_PULLUP;
return EC_SUCCESS;
}
/* There is still some block left to read, stay in READ READY. */
return EC_SUCCESS;
}
static errcode_t
_f_eb_write_ready(dch_t * dch, int * ready)
{
errcode_t ec = EC_SUCCESS;
ebpd_t * ebpd = (ebpd_t *) dch->privdata;
int i = 0;
*ready = 0;
ec = _f_eb_poll(dch);
if (ec)
return ec;
for (i = 0; i < ebpd->dccnt; i++)
{
if (ebpd->dcs[i].state == DC_STATE_READY)
{
*ready = 1;
return ec;
}
}
return ec;
}
static errcode_t
_f_eb_write(dch_t * dch,
char * buf,
globus_off_t off,
size_t len,
int eof)
{
errcode_t ec = EC_SUCCESS;
dc_t * dc = NULL;
ebpd_t * ebpd = (ebpd_t *) dch->privdata;
int i = 0;
off -= dch->partial_off;
if (buf && len)
{
while (!dc)
{
ec = _f_eb_poll(dch);
if (ec)
return ec;
for (i = 0; !dc && i < ebpd->dccnt; i++)
{
if (ebpd->dcs[i].state == DC_STATE_READY)
dc = &ebpd->dcs[i];
}
}
dc->buf = buf;
dc->off = off;
dc->count = len;
dc->buflen = len;
dc->state = DC_STATE_PUSH_HEADER;
}
/* Set state to WRITE_PUSH */
if (!eof)
return ec;
/* Flush data. Send EOF once to each server. */
for (i = 0; i < ebpd->dccnt; i += s_parallel())
{
while (ebpd->dcs[i].state != DC_STATE_READY)
{
ec = _f_eb_poll(dch);
if (ec)
return ec;
}
ebpd->dcs[i].state = DC_STATE_PUSH_EOF;
}
/* Flush EOF. Send EOD. */
for (i = 0; i < ebpd->dccnt; i++)
{
while (ebpd->dcs[i].state != DC_STATE_READY)
{
ec = _f_eb_poll(dch);
if (ec)
return ec;
}
ebpd->dcs[i].state = DC_STATE_PUSH_EOD;
}
/* Flush EOD. */
for (i = 0; i < ebpd->dccnt; i++)
{
while (ebpd->dcs[i].state != DC_STATE_EOD)
{
ec = _f_eb_poll(dch);
if (ec)
return ec;
}
}
return ec;
}
static void
_f_eb_close(dch_t * dch)
{
errcode_t ec = EC_SUCCESS;
ebpd_t * ebpd = NULL;
int i = 0;
int wr = 0;
int rd = 0;
if (!dch->privdata)
return;
ebpd = (ebpd_t *) dch->privdata;
for (i = 0; i < ebpd->dccnt; i++)
{
if (ebpd->dcs[i].state == DC_STATE_CONNECT)
{
do {
rd = wr = 1;
ec = net_poll(ebpd->dcs[i].nh, &rd, &wr, -1);
} while (ec == EC_SUCCESS && !wr && !rd);
ec_destroy(ec);
}
FREE(ebpd->dcs[i].buf);
net_destroy(ebpd->dcs[i].nh);
gsi_destroy(ebpd->dcs[i].gh);
}
FREE(ebpd->dcs);
FREE(dch->privdata);
dch->privdata = NULL;
}
const dci_t Ftp_eb_dci = {
_f_eb_active,
_f_eb_passive,
_f_eb_read_ready,
_f_eb_read,
_f_eb_write_ready,
_f_eb_write,
_f_eb_close,
};
static errcode_t
_f_eb_read_pullup(dc_t * dc)
{
errcode_t ec = EC_SUCCESS;
int rdy = 0;
char * buf = NULL;
size_t len = 0;
int eof = 0;
if (dc->eof)
return ec;
ec = gsi_dc_fl_read(dc->gh, dc->nh);
if (ec)
return ec;
rdy = gsi_dc_ready(dc->gh, dc->nh, 1);
if (!rdy)
return ec;
ec = gsi_dc_read(dc->gh, dc->nh, &buf, &len, &eof);
if (ec)
return ec;
if (eof)
dc->eof = eof;
dc->buf = (char *) realloc(dc->buf, dc->buflen + len);
memcpy(dc->buf + dc->buflen, buf, len);
dc->buflen += len;
Free(buf);
return ec;
}
static errcode_t
_f_eb_header_pullup(ebpd_t * ebpd, dc_t * dc)
{
errcode_t ec = EC_SUCCESS;
int desc = 0;
ec = _f_eb_read_pullup(dc);
if (ec)
return ec;
if (dc->buflen < EB_HEADER_LEN)
return ec;
/* Initialize the count and offset. */
dc->count = 0;
dc->off = 0;
/* Find the descriptor field. */
desc = (int) dc->buf[0];
/* Eod */
if (desc & 0x08)
dc->eod = 1;
/*
* EOF Header. This header is a different format than the others:
* 8 bit descriptor, 64 bits unused, 64 bit expected EOD count
* No data follows this header.
*/
if (desc & 0x40)
{
ebpd->eeods = (((int)dc->buf[13]) << 24) +
(((int)dc->buf[14]) << 16) +
(((int)dc->buf[15]) << 8) +
(((int)dc->buf[16]));
memmove(dc->buf, dc->buf + EB_HEADER_LEN, dc->buflen - EB_HEADER_LEN);
dc->buflen -= EB_HEADER_LEN;
/*
* If we received EOD, we are done (since we can not receive more data
* on this header. Go to READ READY with count = 0 so that we can set
* eof when the caller calls read.
*/
if (dc->eod)
dc->state = DC_STATE_READ_READY;
/* If not eod, stay in header pullup. */
return ec;
}
dc->count = (((globus_off_t)dc->buf[1] & 0xFF) << 56) +
(((globus_off_t)dc->buf[2] & 0xFF) << 48) +
(((globus_off_t)dc->buf[3] & 0xFF) << 40) +
(((globus_off_t)dc->buf[4] & 0xFF) << 32) +
(((globus_off_t)dc->buf[5] & 0xFF) << 24) +
(((globus_off_t)dc->buf[6] & 0xFF) << 16) +
(((globus_off_t)dc->buf[7] & 0xFF) << 8) +
(((globus_off_t)dc->buf[8] & 0xFF));
dc->off = (((globus_off_t)dc->buf[9] & 0xFF) << 56) +
(((globus_off_t)dc->buf[10] & 0xFF) << 48) +
(((globus_off_t)dc->buf[11] & 0xFF) << 40) +
(((globus_off_t)dc->buf[12] & 0xFF) << 32) +
(((globus_off_t)dc->buf[13] & 0xFF) << 24) +
(((globus_off_t)dc->buf[14] & 0xFF) << 16) +
(((globus_off_t)dc->buf[15] & 0xFF) << 8) +
(((globus_off_t)dc->buf[16] & 0xFF));
memmove(dc->buf, dc->buf + EB_HEADER_LEN, dc->buflen - EB_HEADER_LEN);
dc->buflen -= EB_HEADER_LEN;
/* Mark us as read ready. */
dc->state = DC_STATE_READ_READY;
return ec;
}
static errcode_t
_f_eb_poll(dch_t * dch)
{
errcode_t ec = EC_SUCCESS;
int done = 0;
int i = 0;
ebpd_t * ebpd = (ebpd_t *) dch->privdata;
dc_t * dc = NULL;
nh_t * nh = NULL;
for (i = 0; !ec && i < ebpd->dccnt; i++)
{
dc = &ebpd->dcs[i];
switch (dc->state)
{
case DC_STATE_CONNECT:
dc->state = DC_STATE_CONNECT_AUTH;
case DC_STATE_CONNECT_AUTH:
ec = gsi_dc_auth(&dc->gh, dc->nh, dch->pbsz, dch->dcau, 0, &done);
if (!ec && done)
dc->state = DC_STATE_READY;
break;
case DC_STATE_ACCEPT:
ec = net_accept(dc->nh, &nh);
if (ec || !nh)
break;
ebpd->dccnt++;
ebpd->dcs = (dc_t*) realloc(ebpd->dcs, sizeof(dc_t)*ebpd->dccnt);
memset(&ebpd->dcs[ebpd->dccnt-1], 0, sizeof(dc_t));
ebpd->dcs[ebpd->dccnt-1].nh = nh;
ebpd->dcs[ebpd->dccnt-1].state = DC_STATE_ACCEPT_AUTH;
break;
case DC_STATE_ACCEPT_AUTH:
ec = gsi_dc_auth(&dc->gh, dc->nh, dch->pbsz, dch->dcau, 1, &done);
if (!ec && done)
dc->state = DC_STATE_HEADER_PULLUP;
break;
case DC_STATE_HEADER_PULLUP:
ec = _f_eb_header_pullup(ebpd, dc);
break;
case DC_STATE_READ_READY:
/*
* It may be the case that we have already read our entire block or
* perhaps we aren't receiving a block (count = 0). So only bother
* with the read if we know we have data to read.
*/
if (dc->count > dc->buflen)
ec = _f_eb_read_pullup(dc);
break;
case DC_STATE_PUSH_HEADER:
ec = _f_eb_push_header(ebpd, dc);
break;
case DC_STATE_PUSH_DATA:
ec = _f_eb_push_data(ebpd, dc);
break;
case DC_STATE_PUSH_EOD:
ec = _f_eb_push_eod(ebpd, dc);
break;
case DC_STATE_PUSH_EOF:
ec = _f_eb_push_eof(ebpd, dc);
break;
case DC_STATE_FLUSH_HEADER:
case DC_STATE_FLUSH_DATA:
case DC_STATE_FLUSH_EOF:
case DC_STATE_FLUSH_EOD:
ec = gsi_dc_fl_write(dc->gh, dc->nh);
if (gsi_dc_ready(dc->gh, dc->nh, 0))
{
switch (dc->state)
{
case DC_STATE_FLUSH_HEADER:
dc->state = DC_STATE_PUSH_DATA;
break;
case DC_STATE_FLUSH_DATA:
case DC_STATE_FLUSH_EOF:
dc->state = DC_STATE_READY;
break;
case DC_STATE_FLUSH_EOD:
dc->state = DC_STATE_EOD;
ebpd->eods++;
break;
}
}
break;
}
}
return ec;
}
static char *
_f_eb_header(char desc, globus_off_t count, globus_off_t off)
{
char * cptr = (char *) malloc(EB_HEADER_LEN);
cptr[0] = desc;
cptr[1] = (count >> 56) & 0xFF;
cptr[2] = (count >> 48) & 0xFF;
cptr[3] = (count >> 40) & 0xFF;
cptr[4] = (count >> 32) & 0xFF;
cptr[5] = (count >> 24) & 0xFF;
cptr[6] = (count >> 16) & 0xFF;
cptr[7] = (count >> 8) & 0xFF;
cptr[8] = (count >> 0) & 0xFF;
cptr[9] = (off >> 56) & 0xFF;
cptr[10] = (off >> 48) & 0xFF;
cptr[11] = (off >> 40) & 0xFF;
cptr[12] = (off >> 32) & 0xFF;
cptr[13] = (off >> 24) & 0xFF;
cptr[14] = (off >> 16) & 0xFF;
cptr[15] = (off >> 8) & 0xFF;
cptr[16] = (off >> 0) & 0xFF;
return cptr;
}
static errcode_t
_f_eb_push_header(ebpd_t * ebpd, dc_t * dc)
{
errcode_t ec = EC_SUCCESS;
char * header = _f_eb_header(0, dc->count, dc->off);
ec = gsi_dc_write(dc->gh, dc->nh, header, EB_HEADER_LEN, 0);
dc->state = DC_STATE_FLUSH_HEADER;
return ec;
}
static errcode_t
_f_eb_push_eod(ebpd_t * ebpd, dc_t * dc)
{
errcode_t ec = EC_SUCCESS;
/* 0x08 = EOD */
/* 0x04 = Close data channel . */
char * header = _f_eb_header(0x08|0x04, 0, 0);
ec = gsi_dc_write(dc->gh, dc->nh, header, EB_HEADER_LEN, 0);
dc->state = DC_STATE_FLUSH_EOD;
return ec;
}
static errcode_t
_f_eb_push_eof(ebpd_t * ebpd, dc_t * dc)
{
errcode_t ec = EC_SUCCESS;
char * header = _f_eb_header(0x40, 0, s_parallel());
ec = gsi_dc_write(dc->gh, dc->nh, header, EB_HEADER_LEN, 0);
dc->state = DC_STATE_FLUSH_EOF;
return ec;
}
static errcode_t
_f_eb_push_data(ebpd_t * ebpd, dc_t * dc)
{
errcode_t ec = EC_SUCCESS;
ec = gsi_dc_write(dc->gh, dc->nh, dc->buf, dc->buflen, 0);
dc->buf = NULL;
dc->buflen = 0;
dc->count = 0;
dc->off = 0;
dc->state = DC_STATE_FLUSH_DATA;
return ec;
}