File: SocketInput.h

package info (click to toggle)
dasher 4.11%2Bgit20130508.adc653-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 40,248 kB
  • ctags: 5,158
  • sloc: xml: 185,479; cpp: 32,301; sh: 11,207; makefile: 828; ansic: 483
file content (63 lines) | stat: -rw-r--r-- 1,401 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// SocketInput.h
//
// (C) Copyright Seb Wills 2005
//
// Linux-specific subclass of SocketInputBase: provides network socket control of Dasher cursor

#ifndef __SocketInput_h__
#define __SocketInput_h__

#include "./SocketInputBase.h"
#include "./Observable.h"

#include <iostream>
#include <pthread.h>

#define GCC_VERSION (__GNUC__ * 10000 \
                     + __GNUC_MINOR__ * 100 \
                     + __GNUC_PATCHLEVEL__)



namespace Dasher {
  class CSocketInput;
#if GCC_VERSION >= 40100
  void *ThreadLauncherStub(void *_myClass);
#endif

using namespace std;
/// \ingroup Input
/// \{
class CSocketInput:public CSocketInputBase {

  // This non-member launcher stub function is required because pthreads can't launch a non-static member method.
  friend void *ThreadLauncherStub(void *_myClass) {
    CSocketInput *myClass = (CSocketInput *) _myClass;

    pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);     // kill this thread immediately if another thread cancels it
    // don't know how this interacts with recv blocking

    myClass->ReadForever();

    return NULL;
  }

public:

  CSocketInput(CSettingsUser *pCreator, CMessageDisplay *pMsgs);
  ~CSocketInput();

private:

  pthread_t readerThread;

  bool LaunchReaderThread();

  void CancelReaderThread();

  // TODO: should probably override ReportErrnoError() to popup a Gtk error message

};
}
/// \}
#endif