OpenShot Audio Library | OpenShotAudio: juce_Socket.h Source File

OpenShot Audio Library | OpenShotAudio 0.3.0

Loading...
Searching...
No Matches
juce_Socket.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
37 class JUCE_API StreamingSocket final
38{
39public:
40 //==============================================================================
50 StreamingSocket();
51
53 ~StreamingSocket();
54
55 //==============================================================================
61 bool bindToPort (int localPortNumber);
62
74 bool bindToPort (int localPortNumber, const String& localAddress);
75
84 int getBoundPort() const noexcept;
85
94 bool connect (const String& remoteHostname,
95 int remotePortNumber,
96 int timeOutMillisecs = 3000);
97
99 bool isConnected() const noexcept { return connected; }
100
102 void close();
103
105 const String& getHostName() const noexcept { return hostName; }
106
108 int getPort() const noexcept { return portNumber; }
109
111 bool isLocal() const noexcept;
112
114 int getRawSocketHandle() const noexcept { return handle; }
115
116 //==============================================================================
128 int waitUntilReady (bool readyForReading, int timeoutMsecs);
129
140 int read (void* destBuffer, int maxBytesToRead,
141 bool blockUntilSpecifiedAmountHasArrived);
142
150 int write (const void* sourceBuffer, int numBytesToWrite);
151
152 //==============================================================================
166 bool createListener (int portNumber, const String& localHostName = String());
167
177 StreamingSocket* waitForNextConnection() const;
178
179private:
180 //==============================================================================
181 String hostName;
182 std::atomic<int> portNumber { 0 }, handle { -1 };
183 std::atomic<bool> connected { false }, isListener { false };
184 mutable CriticalSection readLock;
185
186 StreamingSocket (const String& hostname, int portNumber, int handle);
187
188 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (StreamingSocket)
189};
190
191
192//==============================================================================
203 class JUCE_API DatagramSocket final
204{
205public:
206 //==============================================================================
215 DatagramSocket (bool enableBroadcasting = false);
216
217
219 ~DatagramSocket();
220
221 //==============================================================================
230 bool bindToPort (int localPortNumber);
231
243 bool bindToPort (int localPortNumber, const String& localAddress);
244
252 int getBoundPort() const noexcept;
253
255 int getRawSocketHandle() const noexcept { return handle; }
256
257 //==============================================================================
269 int waitUntilReady (bool readyForReading, int timeoutMsecs);
270
281 int read (void* destBuffer, int maxBytesToRead,
282 bool blockUntilSpecifiedAmountHasArrived);
283
295 int read (void* destBuffer, int maxBytesToRead,
296 bool blockUntilSpecifiedAmountHasArrived,
297 String& senderIPAddress, int& senderPortNumber);
298
306 int write (const String& remoteHostname, int remotePortNumber,
307 const void* sourceBuffer, int numBytesToWrite);
308
323 void shutdown();
324
325 //==============================================================================
330 bool joinMulticast (const String& multicastIPAddress);
331
336 bool leaveMulticast (const String& multicastIPAddress);
337
342 bool setMulticastLoopbackEnabled (bool enableLoopback);
343
344 //==============================================================================
353 bool setEnablePortReuse (bool enabled);
354
355private:
356 //==============================================================================
357 std::atomic<int> handle { -1 };
358 bool isBound = false;
359 String lastBindAddress, lastServerHost;
360 int lastServerPort = -1;
361 void* lastServerAddress = nullptr;
362 mutable CriticalSection readLock;
363
364 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DatagramSocket)
365};
366
367} // namespace juce
juce::DatagramSocket
Definition: juce_Socket.h:204
juce::DatagramSocket::getRawSocketHandle
int getRawSocketHandle() const noexcept
Definition: juce_Socket.h:255
juce::StreamingSocket
Definition: juce_Socket.h:38
juce::StreamingSocket::getPort
int getPort() const noexcept
Definition: juce_Socket.h:108
juce::StreamingSocket::getHostName
const String & getHostName() const noexcept
Definition: juce_Socket.h:105
juce::StreamingSocket::isConnected
bool isConnected() const noexcept
Definition: juce_Socket.h:99
juce::String
Definition: juce_String.h:39