-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from hackerschoice/filexfer
Filetransfer
- Loading branch information
Showing
52 changed files
with
5,415 additions
and
464 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
SUBDIRS = lib tools man | ||
EXTRA_DIST = README.md config bootstrap include/gsocket LICENSE | ||
EXTRA_DIST = README.md config bootstrap tests/Makefile tests/run_all_tests.sh tests/run_gs_tests.sh tests/run_ft_tests.sh include/gsocket LICENSE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef __GS_BUF_H__ | ||
#define __GS_BUF_H__ 1 | ||
|
||
|
||
typedef struct | ||
{ | ||
void *data; | ||
size_t sz_total; | ||
size_t sz_used; | ||
|
||
size_t sz_max_add; | ||
} GS_BUF; | ||
|
||
void GS_BUF_init(GS_BUF *gsb, size_t sz_min_free); | ||
void GS_BUF_free(GS_BUF *gsb); | ||
int GS_BUF_resize(GS_BUF *gsb, size_t sz_new); | ||
int GS_BUF_add(GS_BUF *gsb, size_t len); | ||
int GS_BUF_add_data(GS_BUF *gsb, void *data, size_t len); | ||
int GS_BUF_del(GS_BUF *gsb, size_t len); | ||
|
||
#define GS_BUF_UNUSED(gsb) ((gsb)->sz_total - (gsb)->sz_used) | ||
#define GS_BUF_RSRC(gsb) (gsb)->data | ||
#define GS_BUF_WDST(gsb) ((uint8_t *)(gsb)->data + (gsb)->sz_used) | ||
#define GS_BUF_USED(gsb) (gsb)->sz_used | ||
|
||
#endif /* !__GS_BUF_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* A FIFO like buffer to. Used by file transfer as a write-buffer to queue | ||
* control messages (such as chn_accept, chn_error, ...). | ||
*/ | ||
#include "gs-common.h" | ||
#include <gsocket/gsocket.h> | ||
#include "gs-externs.h" | ||
|
||
void | ||
GS_BUF_init(GS_BUF *gsb, size_t sz_max_add) | ||
{ | ||
memset(gsb, 0, sizeof *gsb); | ||
gsb->sz_max_add = sz_max_add; | ||
|
||
// gsb->sz_total = 16*1024*1024; // FIXME | ||
// gsb->data = malloc(gsb->sz_total); // FIXME | ||
|
||
GS_BUF_resize(gsb, 0); | ||
} | ||
|
||
void | ||
GS_BUF_free(GS_BUF *gsb) | ||
{ | ||
XFREE(gsb->data); | ||
memset(gsb, 0, sizeof *gsb); | ||
} | ||
|
||
// Adjust size to have at least sz_min_free available. | ||
int | ||
GS_BUF_resize(GS_BUF *gsb, size_t sz_new) | ||
{ | ||
if (GS_BUF_UNUSED(gsb) >= sz_new + gsb->sz_max_add) | ||
return 0; | ||
|
||
gsb->sz_total = gsb->sz_used + sz_new + gsb->sz_max_add; | ||
DEBUGF_R("realloc to %zu, used %zu\n", gsb->sz_total, gsb->sz_used); | ||
gsb->data = realloc(gsb->data, gsb->sz_total); | ||
|
||
return 0; | ||
} | ||
|
||
int | ||
GS_BUF_add(GS_BUF *gsb, size_t len) | ||
{ | ||
// Bail. There is sz_max_add space available but looks like caller wrote | ||
// more ata... | ||
XASSERT(len <= GS_BUF_UNUSED(gsb), "Not enough space in buffer\n"); | ||
|
||
gsb->sz_used += len; | ||
|
||
// Resize | ||
GS_BUF_resize(gsb, 0); | ||
|
||
return 0; | ||
} | ||
|
||
int | ||
GS_BUF_add_data(GS_BUF *gsb, void *data, size_t len) | ||
{ | ||
GS_BUF_resize(gsb, len); | ||
memcpy((uint8_t *)gsb->data + gsb->sz_used, data, len); | ||
|
||
gsb->sz_used += len; | ||
|
||
return 0; | ||
} | ||
|
||
/* | ||
* Consume data from beginning. | ||
*/ | ||
int | ||
GS_BUF_del(GS_BUF *gsb, size_t len) | ||
{ | ||
XASSERT(gsb->sz_used >= len, "Cant. used=%zu, len=%zu\n", gsb->sz_used, len); | ||
gsb->sz_used -= len; | ||
memmove(gsb->data, (uint8_t *)gsb->data + len, gsb->sz_used); | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.