-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
odbc: Remove some duplicated code in timeout3 and freeclose tests
Fake server initialisation function was exactly the same. In the meantime return bool from init_fake_server instead of int. Signed-off-by: Frediano Ziglio <[email protected]>
- Loading branch information
Showing
6 changed files
with
83 additions
and
76 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
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,54 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
|
||
#include "common.h" | ||
|
||
#if HAVE_UNISTD_H | ||
#include <unistd.h> | ||
#endif /* HAVE_UNISTD_H */ | ||
|
||
#include <freetds/time.h> | ||
|
||
#if HAVE_SYS_SOCKET_H | ||
#include <sys/socket.h> | ||
#endif /* HAVE_SYS_SOCKET_H */ | ||
|
||
#if HAVE_NETINET_IN_H | ||
#include <netinet/in.h> | ||
#endif /* HAVE_NETINET_IN_H */ | ||
|
||
#include "fake_thread.h" | ||
|
||
tds_thread fake_thread; | ||
|
||
/* build a listening socket to connect to */ | ||
bool | ||
init_fake_server(int ip_port) | ||
{ | ||
struct sockaddr_in sin; | ||
TDS_SYS_SOCKET s; | ||
|
||
memset(&sin, 0, sizeof(sin)); | ||
sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); | ||
sin.sin_port = htons((short) ip_port); | ||
sin.sin_family = AF_INET; | ||
|
||
if (TDS_IS_SOCKET_INVALID(s = socket(AF_INET, SOCK_STREAM, 0))) { | ||
perror("socket"); | ||
exit(1); | ||
} | ||
if (bind(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) { | ||
perror("bind"); | ||
CLOSESOCKET(s); | ||
return false; | ||
} | ||
if (listen(s, 5) < 0) { | ||
perror("listen"); | ||
CLOSESOCKET(s); | ||
return false; | ||
} | ||
if (tds_thread_create(&fake_thread, fake_thread_proc, TDS_INT2PTR(s)) != 0) { | ||
perror("tds_thread_create"); | ||
exit(1); | ||
} | ||
return true; | ||
} |
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,17 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
#include <freetds/thread.h> | ||
|
||
#include <freetds/pushvis.h> | ||
|
||
extern tds_thread fake_thread; | ||
|
||
/* function to be provided to use init_fake_server() */ | ||
TDS_THREAD_PROC_DECLARE(fake_thread_proc, arg); | ||
|
||
/** | ||
* Initialize fake server and thread with specified TCP port. | ||
* The server will listen on local address. | ||
*/ | ||
bool init_fake_server(int ip_port); | ||
|
||
#include <freetds/popvis.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