2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 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 General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 # include <winsock2.h>
26 typedef int socklen_t
;
27 # define bzero( ptr, count ) memset( ptr, 0, count )
29 #include <sys/types.h>
30 #include <sys/socket.h>
35 #include "boost/atomic.hpp"
37 //////////////////////////////////////////////////////////////////////////////////////////////////////////
45 virtual ReplyFunc
GetReplyFunc()=0;
48 virtual ~SC_CmdPort();
50 virtual void* Run()=0;
53 //////////////////////////////////////////////////////////////////////////////////////////////////////////
55 class SC_ComPort
: public SC_CmdPort
60 struct sockaddr_in mBindSockAddr
;
63 SC_ComPort(int inPortNum
);
64 virtual ~SC_ComPort();
66 int Socket() { return mSocket
; }
68 int PortNum() const { return mPortNum
; }
69 int RealPortNum() const { return ntohs(mBindSockAddr
.sin_port
); }
72 //////////////////////////////////////////////////////////////////////////////////////////////////////////
74 class SC_UdpInPort
: public SC_ComPort
77 struct sockaddr_in mReplySockAddr
;
78 virtual ReplyFunc
GetReplyFunc();
81 SC_UdpInPort(int inPortNum
);
84 int PortNum() const { return mPortNum
; }
89 //////////////////////////////////////////////////////////////////////////////////////////////////////////
91 class SC_UdpCustomInPort
: public SC_ComPort
94 struct sockaddr_in mReplySockAddr
;
95 virtual ReplyFunc
GetReplyFunc();
96 boost::atomic
<bool> mRunning
;
99 SC_UdpCustomInPort(int inPortNum
);
100 ~SC_UdpCustomInPort();
102 int PortNum() const { return mPortNum
; }
107 //////////////////////////////////////////////////////////////////////////////////////////////////////////
109 class SC_TcpInPort
: public SC_ComPort
111 SC_Semaphore mConnectionAvailable
;
115 virtual ReplyFunc
GetReplyFunc();
118 SC_TcpInPort(int inPortNum
, int inMaxConnections
, int inBacklog
);
122 void ConnectionTerminated();
125 //////////////////////////////////////////////////////////////////////////////////////////////////////////
127 class SC_TcpConnectionPort
: public SC_ComPort
129 SC_TcpInPort
*mParent
;
132 virtual ReplyFunc
GetReplyFunc();
135 SC_TcpConnectionPort(SC_TcpInPort
*inParent
, int inSocket
);
136 virtual ~SC_TcpConnectionPort();
141 const int kTextBufSize
= 8192;
143 //////////////////////////////////////////////////////////////////////////////////////////////////////////
145 class SC_TcpClientPort
: public SC_ComPort
148 typedef void (*ClientNotifyFunc
)(void* clientData
);
151 SC_TcpClientPort(int inSocket
, ClientNotifyFunc notifyFunc
=0, void* clientData
=0);
152 virtual ~SC_TcpClientPort();
158 virtual ReplyFunc
GetReplyFunc();
161 struct sockaddr_in mReplySockAddr
;
163 ClientNotifyFunc mClientNotifyFunc
;
167 //////////////////////////////////////////////////////////////////////////////////////////////////////////