Skip to content

Commit 4d4c4fe

Browse files
committed
libvncclient: introduce rfbClient[Connect|Initialise]
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.
1 parent 0958967 commit 4d4c4fe

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

include/rfb/rfbclient.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,8 @@ extern int WaitForMessage(rfbClient* client,unsigned int usecs);
837837
*/
838838
rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,int bytesPerPixel);
839839
/**
840-
* Initializes the client. The format is {PROGRAM_NAME, [OPTIONS]..., HOST}. This
840+
* Initializes the client, doing connect and initialisation in one step.
841+
* The format is {PROGRAM_NAME, [OPTIONS]..., HOST}. This
841842
* function does not initialize the program name if the rfbClient's program
842843
* name is set already. The options are as follows:
843844
* <table>
@@ -861,13 +862,21 @@ rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,int bytesPerPixel)
861862
* </table>
862863
*
863864
* The host may include a port number (delimited by a ':').
864-
* @param client The client to initialize
865+
* @param client The client to initialize. This functions calls rfbClientCleanup() itself on error!
865866
* @param argc The number of arguments to the initializer
866867
* @param argv The arguments to the initializer as an array of NULL terminated
867868
* strings
868869
* @return true if the client was initialized successfully, false otherwise.
869870
*/
870871
rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv);
872+
/**
873+
* Connects the client to the remote. rfbClientInitialise() needs to be called after this.
874+
*/
875+
rfbBool rfbClientConnect(rfbClient* client);
876+
/**
877+
* Initialises the client connections. rfbClientConnect() needs to be called before this.
878+
*/
879+
rfbBool rfbClientInitialise(rfbClient* client);
871880
/**
872881
* Cleans up the client structure and releases the memory allocated for it. You
873882
* should call this when you're done with the rfbClient structure that you

src/libvncclient/vncviewer.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,7 @@ rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,
369369
return client;
370370
}
371371

372-
static rfbBool rfbInitConnection(rfbClient* client)
373-
{
372+
rfbBool rfbClientConnect(rfbClient* client) {
374373
/* Unless we accepted an incoming connection, make a TCP connection to the
375374
given VNC server */
376375

@@ -385,7 +384,11 @@ static rfbBool rfbInitConnection(rfbClient* client)
385384
return FALSE;
386385
}
387386
}
387+
return TRUE;
388+
}
389+
388390

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

391394
if (!InitialiseRFBConnection(client))
@@ -501,7 +504,7 @@ rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv) {
501504
}
502505
}
503506

504-
if(!rfbInitConnection(client)) {
507+
if(!rfbClientConnect(client) || !rfbClientInitialise(client)) {
505508
rfbClientCleanup(client);
506509
return FALSE;
507510
}

0 commit comments

Comments
 (0)