Skip to content

Commit e1c071b

Browse files
committed
Create basic structure for send/recv file
1 parent 403a325 commit e1c071b

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

include/buffer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ int buffer_read_packet (buffer_t *, packet_t *);
3838

3939
int recv_buffer_write (char *data, int len);
4040
int recv_buffer_read (char *data, int len);
41+
int recv_file_buffer_read (int, int *, int, int);
4142

4243
int send_buffer_write (char *data, int len);
4344
int send_packet_buffer_write (packet_t *);
4445
int send_packet_buffer_read (packet_t *);
46+
int send_file_buffer_write (int, int, int, int);
4547

4648
#endif /* end of include guard: BUFFER_H_IBSOFJRY */

include/udt.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,25 @@ int udt_send (socket_t, char *, int, int);
101101
* Receive a file from the socket
102102
*
103103
* @param socket_t The socket to receive from
104-
* @param void* Pointer to the file to store incoming data
104+
* @param int The file descriptor to a writable open file
105105
* @param int64_t The offset position to store. After transfer, contains
106106
* new offset
107107
* @param int64_t The total size to be received
108108
* @param int The size of data block
109109
* @return int64_t Size of data sent, -1 on error
110110
*/
111-
int64_t udt_recvfile(socket_t, void *, int64_t *, int64_t, int);
111+
int64_t udt_recvfile(socket_t, int, int64_t *, int64_t, int);
112112

113113
/**
114114
* Send a file to the socket
115115
*
116116
* @param socket_t The socket to send to
117-
* @param void* The file buffer to send
117+
* @param int The file descriptor to a readable open file
118118
* @param int64_t The offset position to read data
119119
* @param int64_t The total size to be sent
120120
* @param int The size of data block
121121
* @return int64_t Size of data sent, -1 on error
122122
*/
123-
int64_t udt_sendfile(socket_t, void *, int64_t, int64_t, int);
123+
int64_t udt_sendfile(socket_t, int, int64_t, int64_t, int);
124124

125125
#endif /* end of include guard: UDT_H_JDNRQTZQ */

src/api.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,17 @@ int udt_close(socket_t sock)
105105
while (connection.is_open);
106106
return close(sock);
107107
}
108+
109+
int64_t udt_recvfile(socket_t sock, int file, int64_t *offset, int64_t filesize,
110+
int blocksize)
111+
{
112+
if (!connection.is_connected) return -1;
113+
return send_file_buffer_read(file, offset, filesize, blocksize);
114+
}
115+
116+
int64_t udt_sendfile(socket_t sock, int file, int64_t offset, int64_t filesize,
117+
int blocksize)
118+
{
119+
if (!connection.is_connected) return -1;
120+
return send_file_buffer_write(file, offset, filesize, blocksize);
121+
}

src/send_buffer.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#include <stdio.h>
1+
#include <unistd.h>
2+
23
#include "buffer.h"
34
#include "packet.h"
45

@@ -66,3 +67,16 @@ int send_buffer_write(char *data, int len)
6667

6768
return retval;
6869
}
70+
71+
int send_file_buffer_write(int fd, int offset, int size, int blocksize)
72+
{
73+
int pos = offset;
74+
packet_t packet;
75+
int retval;
76+
77+
while (1) {
78+
/* TODO: read file and create packets. */
79+
}
80+
81+
return retval; /* TODO: calculate bytes sent and return */
82+
}

0 commit comments

Comments
 (0)