Skip to content

Commit

Permalink
freemount-client: Add synced_dir()
Browse files Browse the repository at this point in the history
  • Loading branch information
jjuran committed Mar 18, 2021
1 parent 51e3615 commit b0b0a22
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
41 changes: 40 additions & 1 deletion client/freemount-client/freemount/synced.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ namespace freemount

struct request_status
{
dirent_callback dirent;
void* handle;
int out_fd;
int32_t result;
plus::var_string data;

request_status( int fd ) : out_fd( fd ), result( -1 )
request_status( int fd )
{
dirent = 0; // NULL
out_fd = fd;
result = -1;
}
};

Expand Down Expand Up @@ -77,6 +82,19 @@ namespace freemount
return 0;
}

if ( frame.type == Frame_dentry_name )
{
if ( req.dirent )
{
const char* data = (const char*) get_data( frame );
uint32_t size = get_size( frame );

req.dirent( data, size, req.handle );
}

return 0;
}

int result = req.result = get_u32( frame );

if ( frame.type == Frame_result )
Expand All @@ -87,6 +105,27 @@ namespace freemount
throw unexpected_frame_type( frame.type );
}

void synced_dir( int in,
int out,
const plus::string& path,
dirent_callback dirent,
void* x )
{
send_list_request( out, path.data(), path.size() );

request_status req( out );

req.dirent = dirent;
req.handle = x;

const int n = wait_for_result( req, in, &frame_handler, path );

if ( n < 0 )
{
throw path_error( path, -n );
}
}

plus::string synced_get( int in, int out, const plus::string& path )
{
send_read_request( out, path.data(), path.size() );
Expand Down
8 changes: 8 additions & 0 deletions client/freemount-client/freemount/synced.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ namespace freemount

// Functions

typedef void (*dirent_callback)( const char* name, uint32_t size, void* x );

void synced_dir( int in,
int out,
const plus::string& path,
dirent_callback dirent,
void* x );

plus::string synced_get( int in, int out, const plus::string& path );

void synced_put( int in,
Expand Down

0 comments on commit b0b0a22

Please sign in to comment.