|
@@ -28,6 +28,7 @@ OTHER DEALINGS IN THE SOFTWARE.
|
|
|
#include "Config.h"
|
|
#include "Config.h"
|
|
|
#include "Str.h"
|
|
#include "Str.h"
|
|
|
#include "List.h"
|
|
#include "List.h"
|
|
|
|
|
+#include "Types.h"
|
|
|
|
|
|
|
|
namespace crown
|
|
namespace crown
|
|
|
{
|
|
{
|
|
@@ -42,8 +43,8 @@ namespace os
|
|
|
#ifdef LINUX
|
|
#ifdef LINUX
|
|
|
const size_t MAX_OS_PATH_LENGTH = 1024;
|
|
const size_t MAX_OS_PATH_LENGTH = 1024;
|
|
|
const char PATH_SEPARATOR = '/';
|
|
const char PATH_SEPARATOR = '/';
|
|
|
-
|
|
|
|
|
const size_t MAX_OS_EVENTS = 512;
|
|
const size_t MAX_OS_EVENTS = 512;
|
|
|
|
|
+
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WINDOWS
|
|
#ifdef WINDOWS
|
|
@@ -96,6 +97,7 @@ void hide_cursor();
|
|
|
void show_cursor();
|
|
void show_cursor();
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
+
|
|
|
enum OSEventType
|
|
enum OSEventType
|
|
|
{
|
|
{
|
|
|
OSET_NONE = 0,
|
|
OSET_NONE = 0,
|
|
@@ -123,7 +125,102 @@ void push_event(OSEventType type, int data_a, int data_b, int data_c, int dat
|
|
|
//! Returns the event on top of the @a event_queue
|
|
//! Returns the event on top of the @a event_queue
|
|
|
OSEvent& pop_event();
|
|
OSEvent& pop_event();
|
|
|
|
|
|
|
|
-} // namespace os
|
|
|
|
|
|
|
|
|
|
-} // namespace crown
|
|
|
|
|
|
|
|
|
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
|
|
+// Networking
|
|
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
|
|
+
|
|
|
|
|
+struct IPv4Address
|
|
|
|
|
+{
|
|
|
|
|
+ uchar address[4];
|
|
|
|
|
+ ushort port;
|
|
|
|
|
+
|
|
|
|
|
+ uint get_address()
|
|
|
|
|
+ {
|
|
|
|
|
+ uint addr = address[0] << 24 | address[1] << 16 | address[2] << 8 | address[3];
|
|
|
|
|
+
|
|
|
|
|
+ return addr;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ushort get_port()
|
|
|
|
|
+ {
|
|
|
|
|
+ return port;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void set(uint a, ushort p)
|
|
|
|
|
+ {
|
|
|
|
|
+ address[0] = (uchar) a >> 24;
|
|
|
|
|
+ address[1] = (uchar) a >> 16;
|
|
|
|
|
+ address[2] = (uchar) a >> 8;
|
|
|
|
|
+ address[3] = (uchar) a;
|
|
|
|
|
+
|
|
|
|
|
+ port = p;
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+class UDPSocket
|
|
|
|
|
+{
|
|
|
|
|
+ public:
|
|
|
|
|
+
|
|
|
|
|
+ // Constructor
|
|
|
|
|
+ UDPSocket();
|
|
|
|
|
+ // Destructor
|
|
|
|
|
+ ~UDPSocket();
|
|
|
|
|
+ // Open connection
|
|
|
|
|
+ bool open(ushort port);
|
|
|
|
|
+ // Send data through socket
|
|
|
|
|
+ bool send(IPv4Address &receiver, const void* data, int size );
|
|
|
|
|
+ // Receive data through socket
|
|
|
|
|
+ int receive(IPv4Address &sender, void* data, int size);
|
|
|
|
|
+ // Close connection
|
|
|
|
|
+ void close();
|
|
|
|
|
+ // Is connection open?
|
|
|
|
|
+ bool is_open();
|
|
|
|
|
+
|
|
|
|
|
+ private:
|
|
|
|
|
+ // Socket descriptor
|
|
|
|
|
+ int m_socket;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+class TCPSocket
|
|
|
|
|
+{
|
|
|
|
|
+ public:
|
|
|
|
|
+
|
|
|
|
|
+ // Constructor
|
|
|
|
|
+ TCPSocket();
|
|
|
|
|
+ // Destructor
|
|
|
|
|
+ ~TCPSocket();
|
|
|
|
|
+ // Open connection (server side)
|
|
|
|
|
+ bool open(ushort port);
|
|
|
|
|
+ // Connect (client side)
|
|
|
|
|
+ bool connect(IPv4Address& destination);
|
|
|
|
|
+ // Close connection
|
|
|
|
|
+ int close();
|
|
|
|
|
+ // Send data through socket
|
|
|
|
|
+ bool send(const void* data, int size);
|
|
|
|
|
+ // Receive data through socket
|
|
|
|
|
+ int receive(void* data, int size);
|
|
|
|
|
+ // Is connection open?
|
|
|
|
|
+ bool is_open();
|
|
|
|
|
+ // Getter method for socket descriptor
|
|
|
|
|
+ int get_socket_id();
|
|
|
|
|
+ // Getter method for active socket descriptor
|
|
|
|
|
+ int get_active_socket_id();
|
|
|
|
|
+ // Setter method for socket descriptor
|
|
|
|
|
+
|
|
|
|
|
+ private:
|
|
|
|
|
+
|
|
|
|
|
+ void set_socket_id(int socket);
|
|
|
|
|
+ // Setter method for ative socket descriptor
|
|
|
|
|
+ void set_active_socket_id(int socket);
|
|
|
|
|
+
|
|
|
|
|
+ // Generated by ::socket
|
|
|
|
|
+ int m_socket;
|
|
|
|
|
+ // Generated by ::accept
|
|
|
|
|
+ int m_active_socket;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+} // namespace os
|
|
|
|
|
+
|
|
|
|
|
+} // namespace crown
|