X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=Usermode%2FLibraries%2Flibaxwin4.so_src%2Fipc_acessipcpipe.cpp;fp=Usermode%2FLibraries%2Flibaxwin4.so_src%2Fipc_acessipcpipe.cpp;h=87cc6c9315d764ea07f6dfb70977d15163e0612e;hb=845b6f9d90bb87b5e760e4d49aa93b0e003ab750;hp=0000000000000000000000000000000000000000;hpb=67a7fe2bb79eceaf10c572a99bd8345c4e81cf5b;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libaxwin4.so_src/ipc_acessipcpipe.cpp b/Usermode/Libraries/libaxwin4.so_src/ipc_acessipcpipe.cpp new file mode 100644 index 00000000..87cc6c93 --- /dev/null +++ b/Usermode/Libraries/libaxwin4.so_src/ipc_acessipcpipe.cpp @@ -0,0 +1,68 @@ +/* + * AxWin4 Interface Library + * - By John Hodge (thePowersGang) + * + * ipc_acessipcpipe.c + * - Acess2 /Devices/ipcpipe/ IPC Channel + */ +#include "include/common.hpp" +#include "include/CIPCChannel_AcessIPCPipe.hpp" +#include +#include + +namespace AxWin { + +CIPCChannel_AcessIPCPipe::CIPCChannel_AcessIPCPipe(const char *Path) +{ + m_fd = _SysOpen(Path, OPENFLAG_READ|OPENFLAG_WRITE); + if( m_fd == -1 ) { + throw ::std::system_error(errno, ::std::system_category()); + } +} + +CIPCChannel_AcessIPCPipe::~CIPCChannel_AcessIPCPipe() +{ +} + +int CIPCChannel_AcessIPCPipe::FillSelect(fd_set& fds) +{ + FD_SET(m_fd, &fds); + return m_fd+1; +} + +bool CIPCChannel_AcessIPCPipe::HandleSelect(const fd_set& fds) +{ + if( FD_ISSET(m_fd, &fds) ) + { + ::std::vector rxbuf(4096); + size_t len = _SysRead(m_fd, rxbuf.data(), rxbuf.capacity()); + if( len == (size_t)-1 ) + throw ::std::system_error(errno, ::std::system_category()); + rxbuf.resize(len); + _SysDebug("CClient_AcessIPCPipe::HandleReceive - Rx %i/%i bytes", len, rxbuf.capacity()); + //_SysDebugHex("CClient_AcessIPCPipe::HandleReceive", rxbuf.data(), len); + + CDeserialiser msg(rxbuf); + ::AxWin::RecvMessage( msg ); + } + return true; +} + +void CIPCChannel_AcessIPCPipe::Send(CSerialiser& message) +{ + const ::std::vector& serialised = message.Compact(); + if(serialised.size() > 0x1000 ) { + throw ::std::length_error("CIPCChannel_AcessIPCPipe::Send"); + } + _SysDebug("CIPCChannel_AcessIPCPipe::Send(%i bytes)", serialised.size()); + //_SysDebugHex("CIPCChannel_AcessIPCPipe::Send", serialised.data(), serialised.size()); + + size_t rv = _SysWrite(m_fd, serialised.data(), serialised.size()); + if( rv != serialised.size() ) { + throw ::std::system_error(errno, ::std::system_category()); + } +} + + +}; // namespace AxWin +