In synchronous mode, if the driver time out is reached, the server may get desynchron...
[jack2.git] / windows / JackWinNamedPipe.h
blobf0a0a38ee44ec8b2fbd1635e103c3787ee111689
1 /*
2 Copyright (C) 2004-2006 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __JackWinNamedPipe__
21 #define __JackWinNamedPipe__
23 #include "JackChannelTransaction.h"
24 #include <assert.h>
25 #include <stdio.h>
26 #include <windows.h>
28 namespace Jack
31 class JackWinNamedPipe : public JackChannelTransaction
34 protected:
36 HANDLE fNamedPipe;
37 char fName[256];
39 public:
41 JackWinNamedPipe(): fNamedPipe(INVALID_HANDLE_VALUE)
43 JackWinNamedPipe(HANDLE pipe): fNamedPipe(pipe)
45 virtual ~JackWinNamedPipe()
48 virtual int Read(void* data, int len);
49 virtual int Write(void* data, int len);
52 /*!
53 \brief Client named pipe.
56 class JackWinNamedPipeClient : public JackWinNamedPipe
59 public:
61 JackWinNamedPipeClient(): JackWinNamedPipe()
63 JackWinNamedPipeClient(HANDLE pipe): JackWinNamedPipe(pipe)
66 virtual ~JackWinNamedPipeClient()
69 virtual int Connect(const char* dir, int which);
70 virtual int Connect(const char* dir, const char* name, int which);
71 virtual int Close();
72 virtual void SetReadTimeOut(long sec);
73 virtual void SetWriteTimeOut(long sec);
76 class JackWinAsyncNamedPipeClient : public JackWinNamedPipeClient
78 enum kIOState {kIdle = 0, kConnecting, kReading, kWriting};
80 private:
82 bool fPendingIO;
83 kIOState fIOState;
84 OVERLAPPED fOverlap;
86 public:
88 JackWinAsyncNamedPipeClient();
89 JackWinAsyncNamedPipeClient(HANDLE pipe, bool pending);
90 virtual ~JackWinAsyncNamedPipeClient();
92 virtual int Read(void* data, int len);
93 virtual int Write(void* data, int len);
95 HANDLE GetEvent()
97 return fOverlap.hEvent;
100 kIOState GetIOState()
102 return fIOState;
105 bool GetPending()
107 return fPendingIO;
110 int FinishIO();
114 \brief Server named pipe.
117 class JackWinNamedPipeServer : public JackWinNamedPipe
120 public:
122 JackWinNamedPipeServer(): JackWinNamedPipe()
124 virtual ~JackWinNamedPipeServer()
127 virtual int Bind(const char* dir, int which);
128 virtual int Bind(const char* dir, const char* name, int which);
129 virtual bool Accept();
130 virtual JackWinNamedPipeClient* AcceptClient();
131 int Close();
135 \brief Server async named pipe.
138 class JackWinAsyncNamedPipeServer : public JackWinNamedPipeServer
141 public:
143 JackWinAsyncNamedPipeServer(): JackWinNamedPipeServer()
145 virtual ~JackWinAsyncNamedPipeServer()
148 int Bind(const char* dir, int which);
149 int Bind(const char* dir, const char* name, int which);
150 bool Accept();
151 JackWinNamedPipeClient* AcceptClient();
152 int Close();
155 } // end of namespace
158 #endif