Skip to content

Commit

Permalink
libvncclient: introduce rfbClient[Connect|Initialise]
Browse files Browse the repository at this point in the history
These two functions were previously not available in the API, but the code
was called internally by rfbInitClient(). This, however, had the drawback of
not working nicely with repeaters where a client might get blocked after
connect but before initialise without the caller knowing the actual state.
  • Loading branch information
bk138 committed Mar 3, 2025
1 parent 0958967 commit 4d4c4fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
13 changes: 11 additions & 2 deletions include/rfb/rfbclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,8 @@ extern int WaitForMessage(rfbClient* client,unsigned int usecs);
*/
rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,int bytesPerPixel);
/**
* Initializes the client. The format is {PROGRAM_NAME, [OPTIONS]..., HOST}. This
* Initializes the client, doing connect and initialisation in one step.
* The format is {PROGRAM_NAME, [OPTIONS]..., HOST}. This
* function does not initialize the program name if the rfbClient's program
* name is set already. The options are as follows:
* <table>
Expand All @@ -861,13 +862,21 @@ rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,int bytesPerPixel)
* </table>
*
* The host may include a port number (delimited by a ':').
* @param client The client to initialize
* @param client The client to initialize. This functions calls rfbClientCleanup() itself on error!
* @param argc The number of arguments to the initializer
* @param argv The arguments to the initializer as an array of NULL terminated
* strings
* @return true if the client was initialized successfully, false otherwise.
*/
rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv);
/**
* Connects the client to the remote. rfbClientInitialise() needs to be called after this.
*/
rfbBool rfbClientConnect(rfbClient* client);
/**
* Initialises the client connections. rfbClientConnect() needs to be called before this.
*/
rfbBool rfbClientInitialise(rfbClient* client);
/**
* Cleans up the client structure and releases the memory allocated for it. You
* should call this when you're done with the rfbClient structure that you
Expand Down
9 changes: 6 additions & 3 deletions src/libvncclient/vncviewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,7 @@ rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,
return client;
}

static rfbBool rfbInitConnection(rfbClient* client)
{
rfbBool rfbClientConnect(rfbClient* client) {
/* Unless we accepted an incoming connection, make a TCP connection to the
given VNC server */

Expand All @@ -385,7 +384,11 @@ static rfbBool rfbInitConnection(rfbClient* client)
return FALSE;
}
}
return TRUE;
}


rfbBool rfbClientInitialise(rfbClient* client) {
/* Initialise the VNC connection, including reading the password */

if (!InitialiseRFBConnection(client))
Expand Down Expand Up @@ -501,7 +504,7 @@ rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv) {
}
}

if(!rfbInitConnection(client)) {
if(!rfbClientConnect(client) || !rfbClientInitialise(client)) {
rfbClientCleanup(client);
return FALSE;
}
Expand Down

0 comments on commit 4d4c4fe

Please sign in to comment.