Lolly 1.4.27
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
Channel Class Reference

#include <spawn.hpp>

Collaboration diagram for Channel:
Collaboration graph
[legend]

Public Types

enum  Direction { CHOUT = 0 , CHIN = 1 }
 

Public Member Functions

 Channel (int s=2048)
 
void Init (int fd, Direction d)
 
void Init (Direction d)
 
void redirect ()
 
int getPipe () const
 
void read (std::string *str)
 
int write (void *data, int lenght)
 
void close ()
 
void closeUnused ()
 
void wait ()
 
 ~Channel ()
 

Public Attributes

const int sz
 

Private Member Functions

enum Direction otherDirection (Direction t)
 
void restore ()
 

Private Attributes

int toBeClosed
 
int origin
 
int saved
 
int fd
 
std::string * str
 
uintptr_t tid
 

Friends

unsigned int bkgread (void *)
 

Detailed Description

Definition at line 21 of file spawn.hpp.

Member Enumeration Documentation

◆ Direction

Enumerator
CHOUT 
CHIN 

Definition at line 24 of file spawn.hpp.

24{ CHOUT= 0, CHIN= 1 };
@ CHIN
Definition spawn.hpp:24
@ CHOUT
Definition spawn.hpp:24

Constructor & Destructor Documentation

◆ Channel()

Channel::Channel ( int s = 2048)

Definition at line 17 of file spawn.cpp.

17 : sz (s) {
18 origin = -1;
19 saved = -1;
20 fd = -1;
21 toBeClosed= -1;
22 str = NULL;
23 tid = 0;
24}
const int sz
Definition spawn.hpp:38
int fd
Definition spawn.hpp:47
std::string * str
Definition spawn.hpp:48
int saved
Definition spawn.hpp:46
int toBeClosed
Definition spawn.hpp:44
int origin
Definition spawn.hpp:45
uintptr_t tid
Definition spawn.hpp:49
The list class represents a linked list.
Definition list.hpp:48

◆ ~Channel()

Channel::~Channel ( )

Definition at line 100 of file spawn.cpp.

100 {
101 closeUnused ();
102 close ();
103 if (tid) {
104 TerminateThread ((HANDLE) tid, -99);
106 }
107}
void closeUnused()
Definition spawn.cpp:76
void close()
Definition spawn.cpp:68

Member Function Documentation

◆ Init() [1/2]

void Channel::Init ( int fd,
Direction d )

Definition at line 44 of file spawn.cpp.

44 {
45 int pp[2];
46 origin= _fd;
47 if (_pipe (pp, sz, O_NOINHERIT | _O_BINARY) == 0) {
48 fd = pp[d];
50 }
51 else origin= -1;
52}
enum Direction otherDirection(Direction t)
Definition spawn.hpp:41

◆ Init() [2/2]

void Channel::Init ( Direction d)

Definition at line 27 of file spawn.cpp.

27 {
28 int pp[2];
29 if (_pipe (pp, sz, O_NOINHERIT | _O_BINARY) == 0) {
30 int pr[2];
31 if (_pipe (pr, sz, _O_BINARY) == 0) {
32 _close (pr[d]);
35 fd = pp[d];
37 }
38 else _close (pp[d]);
40 }
41}

◆ redirect()

void Channel::redirect ( )

Definition at line 55 of file spawn.cpp.

55 {
56 if (origin < 0) return;
57 saved= _dup (origin);
59}

◆ getPipe()

int Channel::getPipe ( ) const
inline

Definition at line 29 of file spawn.hpp.

29{ return (toBeClosed); }

◆ read()

void Channel::read ( std::string * str)

Definition at line 62 of file spawn.cpp.

62 {
63 str= _str;
64 tid= _beginthreadex (NULL, 0, bkgread, this, 0, NULL);
65}
friend unsigned int bkgread(void *)
Definition spawn.cpp:110

◆ write()

int Channel::write ( void * data,
int lenght )
inline

Definition at line 31 of file spawn.hpp.

31 {
32 return (_write (fd, data, lenght));
33 }

◆ close()

void Channel::close ( )

Definition at line 68 of file spawn.cpp.

68 {
69 if (fd >= 0) {
70 _close (fd);
71 fd= -1;
72 }
73}

◆ closeUnused()

void Channel::closeUnused ( )

Definition at line 76 of file spawn.cpp.

76 {
77 if (toBeClosed >= 0) {
79 toBeClosed= -1;
80 }
81 restore ();
82}
void restore()
Definition spawn.cpp:92

◆ wait()

void Channel::wait ( )

Definition at line 85 of file spawn.cpp.

85 {
86 if (tid && WaitForSingleObject ((HANDLE) tid, 5000) == 0 &&
88 tid= 0;
89}

◆ otherDirection()

enum Direction Channel::otherDirection ( Direction t)
inlineprivate

Definition at line 41 of file spawn.hpp.

41 {
42 return (t == CHOUT ? CHIN : CHOUT);
43 }
blackbox t[13]

◆ restore()

void Channel::restore ( )
private

Definition at line 92 of file spawn.cpp.

92 {
93 if (saved >= 0) {
95 _close (saved);
96 saved= -1;
97 }
98}

Friends And Related Symbol Documentation

◆ bkgread

unsigned int bkgread ( void * )
friend

Definition at line 110 of file spawn.cpp.

110 {
111 char buf[1024];
112 int cnt;
114 do {
115 cnt= _read (that->fd, buf, sizeof (buf));
116 if (cnt > 0) *(that->str)+= std::basic_string<char> (buf, cnt);
117 else if (cnt == 0) that->close ();
118 } while (cnt > 0);
119 return (cnt);
120}
list(T item)
Construct a new list object with a single item.
Definition list.hpp:137

Member Data Documentation

◆ sz

const int Channel::sz

Definition at line 38 of file spawn.hpp.

◆ toBeClosed

int Channel::toBeClosed
private

Definition at line 44 of file spawn.hpp.

◆ origin

int Channel::origin
private

Definition at line 45 of file spawn.hpp.

◆ saved

int Channel::saved
private

Definition at line 46 of file spawn.hpp.

◆ fd

int Channel::fd
private

Definition at line 47 of file spawn.hpp.

◆ str

std::string* Channel::str
private

Definition at line 48 of file spawn.hpp.

◆ tid

uintptr_t Channel::tid
private

Definition at line 49 of file spawn.hpp.


The documentation for this class was generated from the following files: