Add example of the blocking API
This commit is contained in:
+23
-13
@@ -7,7 +7,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// Get definition of "struct pollfd"
|
||||
// Get the definition of "struct pollfd"
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
@@ -67,10 +67,10 @@ typedef struct {
|
||||
// Instanciate a ToastyFS client object. The "addr" and "port"
|
||||
// arguments refer to the address and port of the cluster's
|
||||
// metadata server.
|
||||
Toasty *toasty_init(char *addr, uint16_t port);
|
||||
Toasty *toasty_connect(ToastyString addr, uint16_t port);
|
||||
|
||||
// Release all resources associated to this client
|
||||
void toasty_free(Toasty *tfs);
|
||||
void toasty_disconnect(Toasty *tfs);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// BLOCKING API
|
||||
@@ -83,7 +83,8 @@ int toasty_create_dir(Toasty *tfs, ToastyString path);
|
||||
// Creates a file with the given chunk size at
|
||||
// the specified path. Returns 0 on success, -1
|
||||
// on error. The chunk size can't be 0.
|
||||
int toasty_create_file(Toasty *tfs, ToastyString path, unsigned int chunk_size);
|
||||
int toasty_create_file(Toasty *tfs, ToastyString path,
|
||||
unsigned int chunk_size);
|
||||
|
||||
// Deletes a file or directory at the specified path.
|
||||
// Returns 0 on success, -1 on error.
|
||||
@@ -94,7 +95,8 @@ int toasty_delete(Toasty *tfs, ToastyString path);
|
||||
// on success, returns -1 on error. The listing is
|
||||
// a dynamic array that needs to be freed using
|
||||
// "toasy_free_listing".
|
||||
int toasty_list(Toasty *tfs, ToastyString path, ToastyListing *listing);
|
||||
int toasty_list(Toasty *tfs, ToastyString path,
|
||||
ToastyListing *listing);
|
||||
|
||||
// Frees a listing created by "toasty_list".
|
||||
void toasty_free_listing(ToastyListing *listing);
|
||||
@@ -102,12 +104,14 @@ void toasty_free_listing(ToastyListing *listing);
|
||||
// Reads "len" bytes at offset "off" from the file at
|
||||
// the given path. Returns the number of bytes read on
|
||||
// success, or -1 on error.
|
||||
int toasty_read(Toasty *tfs, ToastyString path, int off, void *dst, int len);
|
||||
int toasty_read(Toasty *tfs, ToastyString path, int off,
|
||||
void *dst, int len);
|
||||
|
||||
// Writes "len" bytes at offset "off" to the file at
|
||||
// the given path. Returns the number of bytes written
|
||||
// on success, or -1 on error.
|
||||
int toasty_write(Toasty *tfs, ToastyString path, int off, void *src, int len);
|
||||
int toasty_write(Toasty *tfs, ToastyString path, int off,
|
||||
void *src, int len);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// ASYNCHRONOUS API
|
||||
@@ -119,7 +123,8 @@ ToastyHandle toasty_begin_create_dir(Toasty *tfs, ToastyString path);
|
||||
|
||||
// Begins a file creation operation and returns a
|
||||
// handle to it. On error, TOASTY_INVALID is returned.
|
||||
ToastyHandle toasty_begin_create_file(Toasty *tfs, ToastyString path, unsigned int chunk_size);
|
||||
ToastyHandle toasty_begin_create_file(Toasty *tfs, ToastyString path,
|
||||
unsigned int chunk_size);
|
||||
|
||||
// Begins a file or directory deletion operation and
|
||||
// returns a handle to it. On error, TOASTY_INVALID is
|
||||
@@ -132,12 +137,14 @@ ToastyHandle toasty_begin_list(Toasty *tfs, ToastyString path);
|
||||
|
||||
// Begins a read operation and returns a handle to it.
|
||||
// On error, TOASTY_INVALID is returned.
|
||||
ToastyHandle toasty_begin_read(Toasty *tfs, ToastyString path, int off, void *dst, int len);
|
||||
ToastyHandle toasty_begin_read(Toasty *tfs, ToastyString path,
|
||||
int off, void *dst, int len);
|
||||
|
||||
// Begins a write operation and returns a handle to it.
|
||||
// On error, TOASTY_INVALID is returned. Note that the source
|
||||
// buffer must be valid until the operation completes.
|
||||
ToastyHandle toasty_begin_write(Toasty *tfs, ToastyString path, int off, void *src, int len);
|
||||
ToastyHandle toasty_begin_write(Toasty *tfs, ToastyString path,
|
||||
int off, void *src, int len);
|
||||
|
||||
// If the operation specified by "handle" is complete,
|
||||
// its result is stored in "result" and 0 is returned.
|
||||
@@ -148,14 +155,16 @@ ToastyHandle toasty_begin_write(Toasty *tfs, ToastyString path, int off, void *s
|
||||
// Note that if a result is returned, handles to that
|
||||
// operation are invalidated.
|
||||
// The "result" must be freed using "toasty_free_result".
|
||||
int toasty_get_result(Toasty *tfs, ToastyHandle handle, ToastyResult *result);
|
||||
int toasty_get_result(Toasty *tfs, ToastyHandle handle,
|
||||
ToastyResult *result);
|
||||
|
||||
// Blocks execution until an operation is complete. This works
|
||||
// like "toasty_get_result", except it waits for "timeout" milliseconds
|
||||
// if the result isn't available. If "timeout" is -1, it waits
|
||||
// indefinitely.
|
||||
// The "result" must be freed using "toasty_free_result".
|
||||
int toasty_wait_result(Toasty *tfs, ToastyHandle handle, ToastyResult *result, int timeout);
|
||||
int toasty_wait_result(Toasty *tfs, ToastyHandle handle,
|
||||
ToastyResult *result, int timeout);
|
||||
|
||||
// Frees resources of a "ToastyResult" previously initialized
|
||||
// by "toasty_get_result" or "toasty_wait_result".
|
||||
@@ -167,7 +176,8 @@ void toasty_free_result(ToastyResult *result);
|
||||
|
||||
// This is a hook for the simulation testing framework.
|
||||
// You shouldn't need to use this.
|
||||
int toasty_process_events(Toasty *tfs, void **contexts, struct pollfd *polled, int num_polled);
|
||||
int toasty_process_events(Toasty *tfs, void **contexts,
|
||||
struct pollfd *polled, int num_polled);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// THE END
|
||||
|
||||
Reference in New Issue
Block a user