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 const int kTextBufSize
= 65536;
76 class SC_UdpInPort
: public SC_ComPort
78 char buf
[kTextBufSize
];
79 struct sockaddr_in mReplySockAddr
;
80 virtual ReplyFunc
GetReplyFunc();
83 SC_UdpInPort(int inPortNum
);
86 int PortNum() const { return mPortNum
; }
91 //////////////////////////////////////////////////////////////////////////////////////////////////////////
93 class SC_UdpCustomInPort
: public SC_ComPort
95 char buf
[kTextBufSize
];
96 struct sockaddr_in mReplySockAddr
;
97 virtual ReplyFunc
GetReplyFunc();
98 boost::atomic
<bool> mRunning
;
101 SC_UdpCustomInPort(int inPortNum
);
102 ~SC_UdpCustomInPort();
104 int PortNum() const { return mPortNum
; }
109 //////////////////////////////////////////////////////////////////////////////////////////////////////////
111 class SC_TcpInPort
: public SC_ComPort
113 SC_Semaphore mConnectionAvailable
;
117 virtual ReplyFunc
GetReplyFunc();
120 SC_TcpInPort(int inPortNum
, int inMaxConnections
, int inBacklog
);
124 void ConnectionTerminated();
127 //////////////////////////////////////////////////////////////////////////////////////////////////////////
129 class SC_TcpConnectionPort
: public SC_ComPort
131 SC_TcpInPort
*mParent
;
134 virtual ReplyFunc
GetReplyFunc();
137 SC_TcpConnectionPort(SC_TcpInPort
*inParent
, int inSocket
);
138 virtual ~SC_TcpConnectionPort();
144 //////////////////////////////////////////////////////////////////////////////////////////////////////////
146 class SC_TcpClientPort
: public SC_ComPort
149 typedef void (*ClientNotifyFunc
)(void* clientData
);
152 SC_TcpClientPort(int inSocket
, ClientNotifyFunc notifyFunc
=0, void* clientData
=0);
153 virtual ~SC_TcpClientPort();
159 virtual ReplyFunc
GetReplyFunc();
162 struct sockaddr_in mReplySockAddr
;
164 ClientNotifyFunc mClientNotifyFunc
;
168 //////////////////////////////////////////////////////////////////////////////////////////////////////////