openshot-audio  0.1.4
juce_Socket.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the juce_core module of the JUCE library.
5  Copyright (c) 2015 - ROLI Ltd.
6 
7  Permission to use, copy, modify, and/or distribute this software for any purpose with
8  or without fee is hereby granted, provided that the above copyright notice and this
9  permission notice appear in all copies.
10 
11  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
12  TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
13  NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
15  IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 
18  ------------------------------------------------------------------------------
19 
20  NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
21  All other JUCE modules are covered by a dual GPL/commercial license, so if you are
22  using any other modules, be sure to check that you also comply with their license.
23 
24  For more details, visit www.juce.com
25 
26  ==============================================================================
27 */
28 
29 #ifndef JUCE_SOCKET_H_INCLUDED
30 #define JUCE_SOCKET_H_INCLUDED
31 
32 
33 //==============================================================================
43 {
44 public:
45  //==============================================================================
56 
58  ~StreamingSocket();
59 
60  //==============================================================================
66  bool bindToPort (int localPortNumber);
67 
78  bool bindToPort (int localPortNumber, const String& localAddress);
79 
85  int getBoundPort() const noexcept;
86 
95  bool connect (const String& remoteHostname,
96  int remotePortNumber,
97  int timeOutMillisecs = 3000);
98 
100  bool isConnected() const noexcept { return connected; }
101 
103  void close();
104 
106  const String& getHostName() const noexcept { return hostName; }
107 
109  int getPort() const noexcept { return portNumber; }
110 
112  bool isLocal() const noexcept;
113 
115  int getRawSocketHandle() const noexcept { return handle; }
116 
117  //==============================================================================
129  int waitUntilReady (bool readyForReading,
130  int timeoutMsecs) const;
131 
142  int read (void* destBuffer, int maxBytesToRead,
143  bool blockUntilSpecifiedAmountHasArrived);
144 
152  int write (const void* sourceBuffer, int numBytesToWrite);
153 
154  //==============================================================================
168  bool createListener (int portNumber, const String& localHostName = String());
169 
179  StreamingSocket* waitForNextConnection() const;
180 
181 private:
182  //==============================================================================
183  String hostName;
184  int volatile portNumber, handle;
185  bool connected, isListener;
186  mutable CriticalSection readLock;
187 
188  StreamingSocket (const String& hostname, int portNumber, int handle);
189 
191 };
192 
193 
194 //==============================================================================
204 {
205 public:
206  //==============================================================================
216  DatagramSocket (bool enableBroadcasting = false);
217 
218 
220  ~DatagramSocket();
221 
222  //==============================================================================
231  bool bindToPort (int localPortNumber);
232 
243  bool bindToPort (int localPortNumber, const String& localAddress);
244 
251  int getBoundPort() const noexcept;
252 
254  int getRawSocketHandle() const noexcept { return handle; }
255 
256  //==============================================================================
268  int waitUntilReady (bool readyForReading,
269  int timeoutMsecs) const;
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 
309  //==============================================================================
314  bool joinMulticast (const String& multicastIPAddress);
315 
320  bool leaveMulticast (const String& multicastIPAddress);
321 
322 private:
323  //==============================================================================
324  int handle;
325  bool isBound;
326  String lastBindAddress, lastServerHost;
327  int lastServerPort;
328  void* lastServerAddress;
329  mutable CriticalSection readLock;
330 
332 };
333 
334 
335 #endif // JUCE_SOCKET_H_INCLUDED
int getRawSocketHandle() const noexcept
Definition: juce_Socket.h:254
Definition: juce_Socket.h:42
#define noexcept
Definition: juce_CompilerSupport.h:141
Definition: juce_String.h:43
#define JUCE_API
Definition: juce_StandardHeader.h:139
const String & getHostName() const noexcept
Definition: juce_Socket.h:106
bool isConnected() const noexcept
Definition: juce_Socket.h:100
Definition: juce_CriticalSection.h:47
int getPort() const noexcept
Definition: juce_Socket.h:109
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition: juce_PlatformDefs.h:198
Definition: juce_Socket.h:203
int getRawSocketHandle() const noexcept
Definition: juce_Socket.h:115