Skip to content

Commit f41f77c

Browse files
authored
updated send_buffer.c
added definition for send_file_buffer_write() as called by udt_sendfile().
1 parent e1c071b commit f41f77c

File tree

1 file changed

+55
-4
lines changed

1 file changed

+55
-4
lines changed

src/send_buffer.c

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include <unistd.h>
2+
#include <sys/types.h>
3+
#include <sys/stat.h>
4+
#include <fcntl.h>
25

36
#include "buffer.h"
47
#include "packet.h"
@@ -70,13 +73,61 @@ int send_buffer_write(char *data, int len)
7073

7174
int send_file_buffer_write(int fd, int offset, int size, int blocksize)
7275
{
73-
int pos = offset;
76+
7477
packet_t packet;
78+
79+
off_t pos;
7580
int retval;
81+
int seqnum;
82+
char *buffer;
83+
int boundary;
84+
int readbytescount;
85+
int packet_dsize;
86+
87+
pos = offset;
88+
retval = size;
89+
seqnum = 2142894844; /* TODO: generate random number */
90+
buffer = (char *) malloc (size);
91+
boundary = PACKET_BOUNDARY_START;
92+
93+
if (fd < 0 || pos < 0) return -1;
94+
95+
packet_dsize = (blocksize > PACKET_DATA_SIZE) ? PACKET_DATA_SIZE : blocksize;
96+
97+
while (size > 0)
98+
{
99+
100+
lseek(fd, pos, SEEK_SET);
101+
readbytescount = read(fd, buffer, packet_dsize);
102+
size -= readbytescount;
103+
104+
boundary = boundary | (size > 0) ? PACKET_BOUNDARY_NONE : PACKET_BOUNDARY_END;
76105

77-
while (1) {
78-
/* TODO: read file and create packets. */
106+
packet_clear_header (packet);
107+
packet_set_data (packet);
108+
packet_set_seqnum (packet, seqnum++);
109+
packet_set_boundary (packet, boundary);
110+
packet_set_order (packet, 1);
111+
packet_set_msgnum (packet, 1);
112+
packet_set_timestamp(packet, 0x0000051c); /* TODO: calculate time */
113+
packet_set_id (packet, 0x08c42c74); /* TODO: generate an id */
114+
115+
packet_new(&packet, buffer, readbytescount);
116+
send_packet_buffer_write(&packet);
117+
118+
boundary = PACKET_BOUNDARY_NONE;
119+
120+
pos += blocksize;
79121
}
122+
123+
packet_clear_header (packet);
124+
packet_set_ctrl (packet);
125+
packet_set_type (packet, PACKET_TYPE_ACK);
126+
packet_set_timestamp(packet, 0x0000051c); /* TODO: calculate time */
127+
packet_set_id (packet, 0x08c42c74); /* TODO: generate an id */
80128

81-
return retval; /* TODO: calculate bytes sent and return */
129+
packet_new(&packet, NULL, 0);
130+
send_packet_buffer_write(&packet);
131+
132+
return retval; /* return total bytes sent */
82133
}

0 commit comments

Comments
 (0)