LCOV - code coverage report
Current view: top level - src/odbc/unittests - fake_thread.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 12 19 63.2 %
Date: 2025-01-18 11:50:39 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: GPL-2.0-or-later */
       2             : 
       3             : #include "common.h"
       4             : 
       5             : #if HAVE_UNISTD_H
       6             : #include <unistd.h>
       7             : #endif /* HAVE_UNISTD_H */
       8             : 
       9             : #include <freetds/time.h>
      10             : 
      11             : #if HAVE_SYS_SOCKET_H
      12             : #include <sys/socket.h>
      13             : #endif /* HAVE_SYS_SOCKET_H */
      14             : 
      15             : #if HAVE_NETINET_IN_H
      16             : #include <netinet/in.h>
      17             : #endif /* HAVE_NETINET_IN_H */
      18             : 
      19             : #include "fake_thread.h"
      20             : 
      21             : tds_thread fake_thread;
      22             : 
      23             : /* build a listening socket to connect to */
      24             : bool
      25          25 : init_fake_server(int ip_port)
      26             : {
      27             :         struct sockaddr_in sin;
      28             :         TDS_SYS_SOCKET s;
      29             : 
      30          25 :         memset(&sin, 0, sizeof(sin));
      31          25 :         sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
      32          25 :         sin.sin_port = htons((short) ip_port);
      33          25 :         sin.sin_family = AF_INET;
      34             : 
      35          25 :         if (TDS_IS_SOCKET_INVALID(s = socket(AF_INET, SOCK_STREAM, 0))) {
      36           0 :                 perror("socket");
      37           0 :                 exit(1);
      38             :         }
      39          25 :         if (bind(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
      40           1 :                 perror("bind");
      41           1 :                 CLOSESOCKET(s);
      42           1 :                 return false;
      43             :         }
      44          24 :         if (listen(s, 5) < 0) {
      45           0 :                 perror("listen");
      46           0 :                 CLOSESOCKET(s);
      47           0 :                 return false;
      48             :         }
      49          48 :         if (tds_thread_create(&fake_thread, fake_thread_proc, TDS_INT2PTR(s)) != 0) {
      50           0 :                 perror("tds_thread_create");
      51           0 :                 exit(1);
      52             :         }
      53             :         return true;
      54             : }

Generated by: LCOV version 1.13