[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tyndur-devel] [PATCH 5/6] tcpip: Readahead-Unterstützung für TCP
+ tcpip: readahead-Callback für TCP implementiert
Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
src/modules/tcpip/lostio_if.c | 46 ++++++++++++++++++++++++++++++++++++++++-
1 files changed, 45 insertions(+), 1 deletions(-)
diff --git a/src/modules/tcpip/lostio_if.c b/src/modules/tcpip/lostio_if.c
index 6269da9..367f682 100644
--- a/src/modules/tcpip/lostio_if.c
+++ b/src/modules/tcpip/lostio_if.c
@@ -79,6 +79,7 @@ typehandle_t typehandle3;
bool lostio_tcp_not_found(char**, uint8_t, pid_t,FILE*);
bool lostio_tcp_pre_open(char**, uint8_t, pid_t,FILE*);
size_t lostio_tcp_read(lostio_filehandle_t*,void*,size_t,size_t);
+size_t lostio_tcp_readahead(lostio_filehandle_t*,void*,size_t,size_t);
size_t lostio_tcp_write(lostio_filehandle_t*,size_t,size_t,void*);
int lostio_tcp_close(lostio_filehandle_t*);
size_t lostio_netconfig_read(lostio_filehandle_t*,void*,size_t,size_t);
@@ -99,6 +100,7 @@ void init_lostio_interface(void)
typehandle.pre_open = &lostio_tcp_pre_open;
typehandle.post_open = NULL;
typehandle.read = &lostio_tcp_read;
+ typehandle.readahead = &lostio_tcp_readahead;
typehandle.write = &lostio_tcp_write;
typehandle.seek = NULL;
typehandle.close = &lostio_tcp_close;;
@@ -202,7 +204,8 @@ bool lostio_tcp_not_found(char** path, uint8_t flags, pid_t pid,
return vfstree_create_node(*path, LOSTIO_TYPES_RAMFILE,
16 * result->ip_count, data, 0);
} else {
- return vfstree_create_node(*path, LOSTIO_TYPES_TCPPORT, 0, NULL, 0);
+ return vfstree_create_node(*path, LOSTIO_TYPES_TCPPORT, 0, NULL,
+ LOSTIO_FLAG_READAHEAD);
}
}
@@ -268,6 +271,47 @@ bool lostio_tcp_pre_open(char** path, uint8_t flags, pid_t pid,
return true;
}
+size_t lostio_tcp_readahead(lostio_filehandle_t* fh, void* buf,
+ size_t bs, size_t bc)
+{
+ struct tcp_connection* conn = fh->node->data;
+ size_t remaining = bs * bc;
+ struct tcp_in_buffer* src;
+ char* dest = buf;
+ size_t bytes_read = 0;
+ int bufidx = 0;
+
+ p();
+ if ((conn->status == TCPS_CLOSED) && (list_is_empty(conn->to_lostio))) {
+ fh->flags |= LOSTIO_FLAG_EOF;
+ }
+
+ while (remaining > 0) {
+ size_t cur_offset;
+ size_t cur_bytes;
+
+ src = list_get_element_at(conn->to_lostio, bufidx++);
+ if (src == NULL) {
+ break;
+ }
+
+ cur_offset = bufidx ? 0 : src->seq;
+ cur_bytes = src->size - src->seq;
+
+ if (cur_bytes > remaining) {
+ cur_bytes = remaining;
+ }
+
+ memcpy(dest, src->data + cur_offset, cur_bytes);
+ remaining -= cur_bytes;
+ dest += cur_bytes;
+ bytes_read += cur_bytes;
+ }
+
+ v();
+ return bytes_read;
+}
+
size_t lostio_tcp_read(lostio_filehandle_t* fh, void* buf,
size_t blocksize, size_t count)
{
--
1.7.7