2 ** NetXMS - Network Management System
3 ** NetXMS Foundation Library
4 ** Copyright (C) 2003-2017 Victor Kirhenshtein
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU Lesser General Public License as published
8 ** by the Free Software Foundation; either version 3 of the License, or
9 ** (at your option) any later version.
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
16 ** You should have received a copy of the GNU Lesser General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "libnetxms.h"
28 * Named pipe listener constructor
30 NamedPipeListener
::NamedPipeListener(const TCHAR
*name
, HPIPE handle
, NamedPipeRequestHandler reqHandler
, void *userArg
, const TCHAR
*user
)
32 nx_strncpy(m_name
, name
, MAX_PIPE_NAME_LEN
);
34 m_reqHandler
= reqHandler
;
36 m_serverThread
= INVALID_THREAD_HANDLE
;
38 nx_strncpy(m_user
, CHECK_NULL_EX(user
), 64);
42 * Start named pipe server
44 void NamedPipeListener
::start()
46 if (m_serverThread
!= INVALID_THREAD_HANDLE
)
47 return; // already started
50 m_serverThread
= ThreadCreateEx(NamedPipeListener
::serverThreadStarter
, 0, this);
54 * Stop named pipe server
56 void NamedPipeListener
::stop()
59 ThreadJoin(m_serverThread
);
60 m_serverThread
= INVALID_THREAD_HANDLE
;
64 * Named pipe server thread starter
66 THREAD_RESULT THREAD_CALL NamedPipeListener
::serverThreadStarter(void *arg
)
68 static_cast<NamedPipeListener
*>(arg
)->serverThread();
73 * Named pipe constructor
75 NamedPipe
::NamedPipe(const TCHAR
*name
, HPIPE handle
, const TCHAR
*user
)
77 nx_strncpy(m_name
, name
, MAX_PIPE_NAME_LEN
);
79 m_writeLock
= MutexCreate();
80 nx_strncpy(m_user
, CHECK_NULL_EX(user
), 64);