ZNC  trunk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ExecSock.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004-2014 ZNC, see the NOTICE file for details.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef EXEC_SOCK_H
18 #define EXEC_SOCK_H
19 
20 #include <znc/zncconfig.h>
21 #include <znc/Socket.h>
22 #include <signal.h>
23 
25 class CExecSock : public CZNCSock {
26 public:
28  m_iPid = -1;
29  }
30 
31  int Execute(const CString & sExec) {
32  int iReadFD, iWriteFD;
33  m_iPid = popen2(iReadFD, iWriteFD, sExec);
34  if (m_iPid != -1) {
35  ConnectFD(iReadFD, iWriteFD, "0.0.0.0:0");
36  }
37  return(m_iPid);
38  }
39  void Kill(int iSignal)
40  {
41  kill(m_iPid, iSignal);
42  Close();
43  }
44  virtual ~CExecSock() {
45  close2(m_iPid, GetRSock(), GetWSock());
46  SetRSock(-1);
47  SetWSock(-1);
48  }
49 
50  int popen2(int & iReadFD, int & iWriteFD, const CString & sCommand);
51  void close2(int iPid, int iReadFD, int iWriteFD);
52 
53 private:
54  int m_iPid;
55 };
56 
57 #endif // !EXEC_SOCK_H
void Kill(int iSignal)
Definition: ExecSock.h:39
void Close(ECloseType eCloseType=CLT_NOW)
just mark us as closed, the parent can pick it up
virtual ~CExecSock()
Definition: ExecSock.h:44
int popen2(int &iReadFD, int &iWriteFD, const CString &sCommand)
Definition: Socket.h:26
void SetWSock(cs_sock_t iSock)
bool ConnectFD(int iReadFD, int iWriteFD, const CS_STRING &sName, bool bIsSSL=false, ETConn eDirection=INBOUND)
Tie this guy to an existing real file descriptor.
cs_sock_t & GetRSock()
returns a reference to the sock
String class that is used inside ZNC.
Definition: ZNCString.h:67
void close2(int iPid, int iReadFD, int iWriteFD)
CExecSock()
Definition: ExecSock.h:27
void SetRSock(cs_sock_t iSock)
cs_sock_t & GetWSock()
Definition: ExecSock.h:25
int Execute(const CString &sExec)
Definition: ExecSock.h:31