MCPcopy Create free account
hub / github.com/Hamlib/Hamlib / start_thread

Function start_thread

src/microham.c:899–1069  ·  view source on GitHub ↗

* If we do not have pthreads, we cannot use the microham device. * This is so because we have to digest unsolicited messages * (e.g. voltage change) and since we have to send periodic * heartbeats. * Nevertheless, the program should compile well even we we do not * have pthreads, in this case start_thread is a dummy since uh_is_initialized * is never set. * * If we do not have socketpair()

Source from the content-addressed store, hash-verified

897 * do not spawn it.
898 */
899static void start_thread()
900{
901#if defined(HAVE_SOCKETPAIR) && defined(HAVE_SELECT)
902 /*
903 * Find a microHam device and open serial port to it.
904 * If successful, create sockets for doing I/O from within hamlib
905 * and start a thread to listen to the "other ends" of the sockets
906 */
907 int ret, fail;
908 unsigned char buf[4];
909 pthread_attr_t attr;
910
911 if (uh_is_initialized)
912 {
913 return; // PARANOIA: this should not happen
914 }
915
916 finddevices();
917
918 if (uh_device_fd < 0)
919 {
920 MYERROR("Could not open any microHam device.\n");
921 return;
922 }
923
924 // Create socket pairs
925 if (socketpair(AF_UNIX, SOCK_STREAM, 0, uh_radio_pair) < 0)
926 {
927 perror("RadioPair:");
928 return;
929 }
930
931 if (socketpair(AF_UNIX, SOCK_STREAM, 0, uh_ptt_pair) < 0)
932 {
933 perror("PTTPair:");
934 return;
935 }
936
937 if (socketpair(AF_UNIX, SOCK_STREAM, 0, uh_wkey_pair) < 0)
938 {
939 perror("WkeyPair:");
940 return;
941 }
942
943 DEBUG("RADIO sockets: server=%d client=%d\n", uh_radio_pair[0],
944 uh_radio_pair[1]);
945 DEBUG("PTT sockets: server=%d client=%d\n", uh_ptt_pair[0], uh_ptt_pair[1]);
946 DEBUG("WinKey sockets: server=%d client=%d\n", uh_wkey_pair[0],
947 uh_wkey_pair[1]);
948
949 //
950 // Make the sockets nonblocking
951 // First try if we can set flags, then do set the flags
952 //
953
954 fail = 0;
955
956 ret = fcntl(uh_radio_pair[0], F_GETFL, 0);

Callers 3

uh_open_pttFunction · 0.70
uh_open_wkeyFunction · 0.70
uh_open_radioFunction · 0.70

Calls 6

finddevicesFunction · 0.85
close_all_filesFunction · 0.85
heartbeatFunction · 0.85
writeControlFunction · 0.85
pthread_attr_initFunction · 0.85
pthread_createFunction · 0.85

Tested by

no test coverage detected