partial sync with network module changes
* SocketTCP/UDP -> TcpSocket * Ftp.makeDirectory -> createDirectory * some SocketSelector fixes + unfinished TcpListener git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1514 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
1464a35711
commit
eada18b7e5
@ -31,7 +31,8 @@ public import
|
||||
dsfml.network.http,
|
||||
dsfml.network.ipaddress,
|
||||
dsfml.network.packet,
|
||||
dsfml.network.selector,
|
||||
dsfml.network.socketselector,
|
||||
dsfml.network.socketstatus,
|
||||
dsfml.network.sockettcp,
|
||||
dsfml.network.socketudp;
|
||||
dsfml.network.tcpsocket,
|
||||
dsfml.network.udpsocket,
|
||||
dsfml.network.tcplistener ;
|
||||
|
@ -453,9 +453,9 @@ class Ftp : DSFMLObject
|
||||
* Returns:
|
||||
* Server response to the request
|
||||
*/
|
||||
FtpResponse makeDirectory(string name)
|
||||
FtpResponse createDirectory(string name)
|
||||
{
|
||||
return new FtpResponse(sfFtp_MakeDirectory(m_ptr, toStringz(name)));
|
||||
return new FtpResponse(sfFtp_CreateDirectory(m_ptr, toStringz(name)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -549,7 +549,7 @@ private:
|
||||
typedef SFMLClass function(SFMLClass, cchar*) pf_sfFtp_GetDirectoryListing;
|
||||
typedef SFMLClass function(SFMLClass, cchar*) pf_sfFtp_ChangeDirectory;
|
||||
typedef SFMLClass function(SFMLClass) pf_sfFtp_ParentDirectory;
|
||||
typedef SFMLClass function(SFMLClass, cchar*) pf_sfFtp_MakeDirectory;
|
||||
typedef SFMLClass function(SFMLClass, cchar*) pf_sfFtp_CreateDirectory;
|
||||
typedef SFMLClass function(SFMLClass, cchar*) pf_sfFtp_DeleteDirectory;
|
||||
typedef SFMLClass function(SFMLClass, cchar*, cchar*) pf_sfFtp_RenameFile;
|
||||
typedef SFMLClass function(SFMLClass, cchar*) pf_sfFtp_DeleteFile;
|
||||
@ -567,7 +567,7 @@ private:
|
||||
static pf_sfFtp_GetDirectoryListing sfFtp_GetDirectoryListing;
|
||||
static pf_sfFtp_ChangeDirectory sfFtp_ChangeDirectory;
|
||||
static pf_sfFtp_ParentDirectory sfFtp_ParentDirectory;
|
||||
static pf_sfFtp_MakeDirectory sfFtp_MakeDirectory;
|
||||
static pf_sfFtp_CreateDirectory sfFtp_CreateDirectory;
|
||||
static pf_sfFtp_DeleteDirectory sfFtp_DeleteDirectory;
|
||||
static pf_sfFtp_RenameFile sfFtp_RenameFile;
|
||||
static pf_sfFtp_DeleteFile sfFtp_DeleteFile;
|
||||
@ -592,7 +592,7 @@ private:
|
||||
sfFtp_GetDirectoryListing = cast(pf_sfFtp_GetDirectoryListing)dll.getSymbol("sfFtp_GetDirectoryListing");
|
||||
sfFtp_ChangeDirectory = cast(pf_sfFtp_ChangeDirectory)dll.getSymbol("sfFtp_ChangeDirectory");
|
||||
sfFtp_ParentDirectory = cast(pf_sfFtp_ParentDirectory)dll.getSymbol("sfFtp_ParentDirectory");
|
||||
sfFtp_MakeDirectory = cast(pf_sfFtp_MakeDirectory)dll.getSymbol("sfFtp_MakeDirectory");
|
||||
sfFtp_sfFtp_CreateDirectoryDirectory = cast(pf_sfFtp_CreateDirectory)dll.getSymbol("sfFtp_CreateDirectory");
|
||||
sfFtp_DeleteDirectory = cast(pf_sfFtp_DeleteDirectory)dll.getSymbol("sfFtp_DeleteDirectory");
|
||||
sfFtp_RenameFile = cast(pf_sfFtp_RenameFile)dll.getSymbol("sfFtp_RenameFile");
|
||||
sfFtp_DeleteFile = cast(pf_sfFtp_DeleteFile)dll.getSymbol("sfFtp_DeleteFile");
|
||||
|
@ -208,7 +208,7 @@ class Http : DSFMLObject
|
||||
{
|
||||
super(sfHttpRequest_Create());
|
||||
sfHttpRequest_SetMethod(m_ptr, requestMethod);
|
||||
sfHttpRequest_SetURI(m_ptr, toStringz(uri));
|
||||
sfHttpRequest_SetUri(m_ptr, toStringz(uri));
|
||||
sfHttpRequest_SetBody(m_ptr, toStringz(requestBody));
|
||||
}
|
||||
|
||||
@ -242,9 +242,9 @@ class Http : DSFMLObject
|
||||
* uri = URI to request, local to the host.
|
||||
* Returns:
|
||||
*/
|
||||
void setURI(string uri)
|
||||
void setUri(string uri)
|
||||
{
|
||||
sfHttpRequest_SetURI(m_ptr, toStringz(uri));
|
||||
sfHttpRequest_SetUri(m_ptr, toStringz(uri));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -280,7 +280,7 @@ class Http : DSFMLObject
|
||||
typedef void function(SFMLClass) pf_sfHttpRequest_Destroy;
|
||||
typedef void function(SFMLClass, cchar*, cchar*) pf_sfHttpRequest_SetField;
|
||||
typedef void function(SFMLClass, HttpMethod) pf_sfHttpRequest_SetMethod;
|
||||
typedef void function(SFMLClass, cchar*) pf_sfHttpRequest_SetURI;
|
||||
typedef void function(SFMLClass, cchar*) pf_sfHttpRequest_SetUri;
|
||||
typedef void function(SFMLClass, uint, uint) pf_sfHttpRequest_SetHttpVersion;
|
||||
typedef void function(SFMLClass, cchar*) pf_sfHttpRequest_SetBody;
|
||||
|
||||
@ -288,7 +288,7 @@ class Http : DSFMLObject
|
||||
static pf_sfHttpRequest_Destroy sfHttpRequest_Destroy;
|
||||
static pf_sfHttpRequest_SetField sfHttpRequest_SetField;
|
||||
static pf_sfHttpRequest_SetMethod sfHttpRequest_SetMethod;
|
||||
static pf_sfHttpRequest_SetURI sfHttpRequest_SetURI;
|
||||
static pf_sfHttpRequest_SetUri sfHttpRequest_SetUri;
|
||||
static pf_sfHttpRequest_SetHttpVersion sfHttpRequest_SetHttpVersion;
|
||||
static pf_sfHttpRequest_SetBody sfHttpRequest_SetBody;
|
||||
}
|
||||
@ -301,7 +301,7 @@ class Http : DSFMLObject
|
||||
sfHttpRequest_Destroy = cast(pf_sfHttpRequest_Destroy)dll.getSymbol("sfHttpRequest_Destroy");
|
||||
sfHttpRequest_SetField = cast(pf_sfHttpRequest_SetField)dll.getSymbol("sfHttpRequest_SetField");
|
||||
sfHttpRequest_SetMethod = cast(pf_sfHttpRequest_SetMethod)dll.getSymbol("sfHttpRequest_SetMethod");
|
||||
sfHttpRequest_SetURI = cast(pf_sfHttpRequest_SetURI)dll.getSymbol("sfHttpRequest_SetURI");
|
||||
sfHttpRequest_SetUri = cast(pf_sfHttpRequest_SetUri)dll.getSymbol("sfHttpRequest_SetUri");
|
||||
sfHttpRequest_SetHttpVersion = cast(pf_sfHttpRequest_SetHttpVersion)dll.getSymbol("sfHttpRequest_SetHttpVersion");
|
||||
sfHttpRequest_SetBody = cast(pf_sfHttpRequest_SetBody)dll.getSymbol("sfHttpRequest_SetBody");
|
||||
}
|
||||
|
@ -24,36 +24,29 @@
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.network.selector;
|
||||
module dsfml.network.socketselector;
|
||||
|
||||
import dsfml.network.sockettcp;
|
||||
import dsfml.network.socketudp;
|
||||
import dsfml.network.tcpsocket;
|
||||
import dsfml.network.udpsocket;
|
||||
|
||||
import dsfml.system.common;
|
||||
|
||||
/**
|
||||
* Selector TCP allow reading from multiple sockets
|
||||
* without blocking. It's a kind of multiplexer. Use SocketTCP or
|
||||
* SocketUDP aliases.
|
||||
* Multiplexer that allows to read from multiple sockets
|
||||
*/
|
||||
class Selector(T) : DSFMLObject
|
||||
class SocketSelector : DSFMLObject
|
||||
{
|
||||
//Ensure type is correct
|
||||
static if (!is(T : SocketTCP) && !is(T : SocketUDP))
|
||||
static assert("Only SocketTCP and SocketUDP are valid for Selector.");
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfSelector_Create());
|
||||
super(sfSocketSelector_Create());
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfSelector_Destroy(m_ptr);
|
||||
sfSocketSelector_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,7 +59,7 @@ class Selector(T) : DSFMLObject
|
||||
{
|
||||
if (!(socket.nativePointer in m_watchedSockets))
|
||||
{
|
||||
sfSelector_Add(m_ptr, socket.nativePointer);
|
||||
sfSocketSelector_Add(m_ptr, socket.nativePointer);
|
||||
m_watchedSockets[socket.nativePointer] = socket;
|
||||
m_numSocketsWatched++;
|
||||
}
|
||||
@ -82,7 +75,7 @@ class Selector(T) : DSFMLObject
|
||||
{
|
||||
if (socket.nativePointer in m_watchedSockets)
|
||||
{
|
||||
sfSelector_Remove(m_ptr, socket.nativePointer);
|
||||
sfSocketSelector_Remove(m_ptr, socket.nativePointer);
|
||||
m_watchedSockets.remove(socket.nativePointer);
|
||||
m_numSocketsWatched--;
|
||||
}
|
||||
@ -93,7 +86,7 @@ class Selector(T) : DSFMLObject
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
sfSelector_Clear(m_ptr);
|
||||
sfSocketSelector_Clear(m_ptr);
|
||||
foreach(key; m_watchedSockets.keys)
|
||||
m_watchedSockets.remove(key);
|
||||
m_numSocketsWatched = 0;
|
||||
@ -112,7 +105,7 @@ class Selector(T) : DSFMLObject
|
||||
*/
|
||||
uint wait(float timeout = 0.f)
|
||||
{
|
||||
return sfSelector_Wait(m_ptr, timeout);
|
||||
return sfSocketSelector_Wait(m_ptr, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,63 +121,33 @@ class Selector(T) : DSFMLObject
|
||||
*/
|
||||
T GetSocketsReady(uint index)
|
||||
{
|
||||
return m_watchedSockets[sfSelector_GetSocketReady(m_ptr, index)];
|
||||
return m_watchedSockets[sfSocketSelector_GetSocketReady(m_ptr, index)];
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
size_t m_numSocketsWatched;
|
||||
T[void*] m_watchedSockets;
|
||||
// size_t m_numSocketsWatched;
|
||||
// T[void*] m_watchedSockets;
|
||||
|
||||
// External ====================================================================
|
||||
extern (C)
|
||||
static extern(C)
|
||||
{
|
||||
typedef SFMLClass function() pf_sfSelector_Create;
|
||||
typedef void function(SFMLClass) pf_sfSelector_Destroy;
|
||||
typedef void function(SFMLClass, SFMLClass) pf_sfSelector_Add;
|
||||
typedef void function(SFMLClass, SFMLClass) pf_sfSelector_Remove;
|
||||
typedef void function(SFMLClass) pf_sfSelector_Clear;
|
||||
typedef uint function(SFMLClass, float) pf_sfSelector_Wait;
|
||||
typedef SFMLClass function(SFMLClass, uint) pf_sfSelector_GetSocketReady;
|
||||
|
||||
static pf_sfSelector_Create sfSelector_Create;
|
||||
static pf_sfSelector_Destroy sfSelector_Destroy;
|
||||
static pf_sfSelector_Add sfSelector_Add;
|
||||
static pf_sfSelector_Remove sfSelector_Remove;
|
||||
static pf_sfSelector_Clear sfSelector_Clear;
|
||||
static pf_sfSelector_Wait sfSelector_Wait;
|
||||
static pf_sfSelector_GetSocketReady sfSelector_GetSocketReady;
|
||||
SFMLClass function() sfSocketSelector_Create;
|
||||
void function(SFMLClass) sfSocketSelector_Destroy;
|
||||
void function(SFMLClass, SFMLClass) sfSocketSelector_AddTcpListener;
|
||||
void function(SFMLClass, SFMLClass) sfSocketSelector_AddTcpSocket;
|
||||
void function(SFMLClass, SFMLClass) sfSocketSelector_AddUdpSocket;
|
||||
void function(SFMLClass, SFMLClass) sfSocketSelector_RemoveTcpListener;
|
||||
void function(SFMLClass, SFMLClass) sfSocketSelector_RemoveTcpSocket;
|
||||
void function(SFMLClass, SFMLClass) sfSocketSelector_RemoveUdpSocket;
|
||||
void function(SFMLClass) sfSocketSelector_Clear;
|
||||
bool function(SFMLClass, float) sfSocketSelector_Wait;
|
||||
bool function(SFMLClass, SFMLClass) sfSocketSelector_IsTcpListenerReady;
|
||||
bool function(SFMLClass, SFMLClass) sfSocketSelector_IsTcpSocketReady;
|
||||
bool function(SFMLClass, SFMLClass) sfSocketSelector_IsUdpSocketReady;
|
||||
}
|
||||
|
||||
static this()
|
||||
{
|
||||
debug
|
||||
DllLoader dll = DllLoader.load("csfml-network-d");
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-network");
|
||||
|
||||
static if (is (T : SocketTCP))
|
||||
{
|
||||
string symbol = "sfSelectorTCP";
|
||||
}
|
||||
else static if (is (T : SocketUDP))
|
||||
{
|
||||
string symbol = "sfSelectorUDP";
|
||||
}
|
||||
|
||||
sfSelector_Add = cast(pf_sfSelector_Add)dll.getSymbol(symbol ~ "_Add");
|
||||
sfSelector_Clear = cast(pf_sfSelector_Clear)dll.getSymbol(symbol ~ "_Clear");
|
||||
sfSelector_Create = cast(pf_sfSelector_Create)dll.getSymbol(symbol ~ "_Create");
|
||||
sfSelector_Destroy = cast(pf_sfSelector_Destroy)dll.getSymbol(symbol ~ "_Destroy");
|
||||
sfSelector_GetSocketReady = cast(pf_sfSelector_GetSocketReady)dll.getSymbol(symbol ~ "_GetSocketReady");
|
||||
sfSelector_Wait = cast(pf_sfSelector_Wait)dll.getSymbol(symbol ~ "_Wait");
|
||||
sfSelector_Remove = cast(pf_sfSelector_Remove)dll.getSymbol(symbol ~ "_Remove");
|
||||
}
|
||||
mixin(loadFromSharedLib2("csfml-network", "sfSocketSelector",
|
||||
"Create", "Destroy", "AddTcpListener", "AddTcpSocket", "AddUdpSocket", "RemoveTcpListener", "RemoveTcpSocket", "RemoveUdpSocket",
|
||||
"Clear", "Wait", "IsTcpListenerReady", "IsTcpSocketReady", "IsUdpSocketReady"));
|
||||
}
|
||||
|
||||
/**
|
||||
* alias of selector for TCP or UDP Socket.
|
||||
*/
|
||||
alias Selector!(SocketTCP) SelectorTCP;
|
||||
/// ditto
|
||||
alias Selector!(SocketUDP) SelectorUDP;
|
49
DSFML/import/dsfml/network/tcplistener.d
Normal file
49
DSFML/import/dsfml/network/tcplistener.d
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* DSFML - SFML Library wrapper for the D programming language.
|
||||
* Copyright (C) 2010 Andreas Hollandt
|
||||
*
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.network.tcplistener;
|
||||
|
||||
import dsfml.network.socketstatus;
|
||||
import dsfml.system.common;
|
||||
|
||||
class TcpListener : DSFMLObject
|
||||
{
|
||||
private:
|
||||
public:
|
||||
|
||||
private:
|
||||
static extern(C)
|
||||
{
|
||||
SFMLClass function() sfTcpListener_Create;
|
||||
void function(SFMLClass) sfTcpListener_Destroy;
|
||||
void function(SFMLClass, bool) sfTcpListener_SetBlocking;
|
||||
bool function(SFMLClass) sfTcpListener_IsBlocking;
|
||||
SocketStatus function(SFMLClass, ushort) sfTcpListener_Listen;
|
||||
SocketStatus function(SFMLClass, SFMLClass*) sfTcpListener_Accept;
|
||||
}
|
||||
|
||||
mixin(loadFromSharedLib2("csfml-network", "sfTcpListener",
|
||||
"Create", "Destroy", "SetBlocking", "IsBlocking", "Listen", "Accept"));
|
||||
}
|
@ -24,7 +24,7 @@
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.network.sockettcp;
|
||||
module dsfml.network.tcpsocket;
|
||||
|
||||
import dsfml.network.ipaddress;
|
||||
import dsfml.network.packet;
|
||||
@ -33,22 +33,22 @@ import dsfml.network.socketstatus;
|
||||
import dsfml.system.common;
|
||||
|
||||
/**
|
||||
* SocketTCP wraps a socket using TCP protocol to send data safely (but a bit slower)
|
||||
* TcpSocket wraps a socket using TCP protocol to send data safely (but a bit slower)
|
||||
*/
|
||||
class SocketTCP : DSFMLObject
|
||||
class TcpSocket : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfSocketTCP_Create());
|
||||
super(sfTcpSocket_Create());
|
||||
m_intermediatePacket = new Packet();
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfSocketTCP_Destroy(m_ptr);
|
||||
sfTcpSocket_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,7 +64,7 @@ class SocketTCP : DSFMLObject
|
||||
*/
|
||||
bool connect(ushort port, IPAddress hostAddress, float timeout = 0.f)
|
||||
{
|
||||
return cast(bool) !sfSocketTCP_Connect(m_ptr, port, hostAddress, timeout);
|
||||
return cast(bool) !sfTcpSocket_Connect(m_ptr, port, hostAddress, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,7 +78,7 @@ class SocketTCP : DSFMLObject
|
||||
*/
|
||||
bool listen(ushort port)
|
||||
{
|
||||
return cast(bool)sfSocketTCP_Listen(m_ptr, port);
|
||||
return cast(bool)sfTcpSocket_Listen(m_ptr, port);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,10 +91,10 @@ class SocketTCP : DSFMLObject
|
||||
* Returns:
|
||||
* Status code
|
||||
*/
|
||||
SocketStatus accept(SocketTCP connected)
|
||||
SocketStatus accept(TcpSocket connected)
|
||||
{
|
||||
SFMLClass temp = null;
|
||||
SocketStatus ret = sfSocketTCP_Accept(m_ptr, &temp, null);
|
||||
SocketStatus ret = sfTcpSocket_Accept(m_ptr, &temp, null);
|
||||
connected.m_ptr = temp;
|
||||
return ret;
|
||||
}
|
||||
@ -110,10 +110,10 @@ class SocketTCP : DSFMLObject
|
||||
* Returns:
|
||||
* Status code
|
||||
*/
|
||||
SocketStatus accept(SocketTCP connected, out IPAddress address)
|
||||
SocketStatus accept(TcpSocket connected, out IPAddress address)
|
||||
{
|
||||
SFMLClass temp = null;
|
||||
SocketStatus ret = sfSocketTCP_Accept(m_ptr, &temp, &address);
|
||||
SocketStatus ret = sfTcpSocket_Accept(m_ptr, &temp, &address);
|
||||
connected.m_ptr = temp;
|
||||
return ret;
|
||||
}
|
||||
@ -134,7 +134,7 @@ class SocketTCP : DSFMLObject
|
||||
}
|
||||
body
|
||||
{
|
||||
return cast(SocketStatus)sfSocketTCP_Send(m_ptr, data.ptr, data.length);
|
||||
return cast(SocketStatus)sfTcpSocket_Send(m_ptr, data.ptr, data.length);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,7 +159,7 @@ class SocketTCP : DSFMLObject
|
||||
}
|
||||
body
|
||||
{
|
||||
return cast(SocketStatus)sfSocketTCP_Receive(m_ptr, data.ptr, data.length, &sizeReceived);
|
||||
return cast(SocketStatus)sfTcpSocket_Receive(m_ptr, data.ptr, data.length, &sizeReceived);
|
||||
}
|
||||
|
||||
|
||||
@ -177,7 +177,7 @@ class SocketTCP : DSFMLObject
|
||||
{
|
||||
byte[] dataArray = packetToSend.onSend();
|
||||
m_intermediatePacket.append(dataArray);
|
||||
SocketStatus stat = cast(SocketStatus)sfSocketTCP_SendPacket(m_ptr, m_intermediatePacket.nativePointer);
|
||||
SocketStatus stat = cast(SocketStatus)sfTcpSocket_SendPacket(m_ptr, m_intermediatePacket.nativePointer);
|
||||
m_intermediatePacket.clear();
|
||||
return stat;
|
||||
}
|
||||
@ -195,7 +195,7 @@ class SocketTCP : DSFMLObject
|
||||
*/
|
||||
SocketStatus receive(Packet packetToReceive)
|
||||
{
|
||||
SocketStatus stat = cast(SocketStatus)sfSocketTCP_ReceivePacket(m_ptr, m_intermediatePacket.nativePointer);
|
||||
SocketStatus stat = cast(SocketStatus)sfTcpSocket_ReceivePacket(m_ptr, m_intermediatePacket.nativePointer);
|
||||
packetToReceive.onReceive(m_intermediatePacket.getData);
|
||||
m_intermediatePacket.clear();
|
||||
return stat;
|
||||
@ -211,7 +211,7 @@ class SocketTCP : DSFMLObject
|
||||
*/
|
||||
bool isValid()
|
||||
{
|
||||
return cast(bool)sfSocketTCP_IsValid(m_ptr);
|
||||
return cast(bool)sfTcpSocket_IsValid(m_ptr);
|
||||
}
|
||||
|
||||
package:
|
||||
@ -229,27 +229,27 @@ private:
|
||||
// External ====================================================================
|
||||
extern (C)
|
||||
{
|
||||
typedef SFMLClass function() pf_sfSocketTCP_Create;
|
||||
typedef void function(SFMLClass) pf_sfSocketTCP_Destroy;
|
||||
typedef int function(SFMLClass, ushort, IPAddress, float) pf_sfSocketTCP_Connect;
|
||||
typedef int function(SFMLClass, ushort) pf_sfSocketTCP_Listen;
|
||||
typedef SocketStatus function(SFMLClass, SFMLClass*, IPAddress*) pf_sfSocketTCP_Accept;
|
||||
typedef SocketStatus function(SFMLClass, const(byte)*, size_t) pf_sfSocketTCP_Send;
|
||||
typedef SocketStatus function(SFMLClass, byte*, size_t, size_t*) pf_sfSocketTCP_Receive;
|
||||
typedef SocketStatus function(SFMLClass, SFMLClass) pf_sfSocketTCP_SendPacket;
|
||||
typedef SocketStatus function(SFMLClass, SFMLClass) pf_sfSocketTCP_ReceivePacket;
|
||||
typedef int function(SFMLClass) pf_sfSocketTCP_IsValid;
|
||||
typedef SFMLClass function() pf_sfTcpSocket_Create;
|
||||
typedef void function(SFMLClass) pf_sfTcpSocket_Destroy;
|
||||
typedef int function(SFMLClass, ushort, IPAddress, float) pf_sfTcpSocket_Connect;
|
||||
typedef int function(SFMLClass, ushort) pf_sfTcpSocket_Listen;
|
||||
typedef SocketStatus function(SFMLClass, SFMLClass*, IPAddress*) pf_sfTcpSocket_Accept;
|
||||
typedef SocketStatus function(SFMLClass, const(byte)*, size_t) pf_sfTcpSocket_Send;
|
||||
typedef SocketStatus function(SFMLClass, byte*, size_t, size_t*) pf_sfTcpSocket_Receive;
|
||||
typedef SocketStatus function(SFMLClass, SFMLClass) pf_sfTcpSocket_SendPacket;
|
||||
typedef SocketStatus function(SFMLClass, SFMLClass) pf_sfTcpSocket_ReceivePacket;
|
||||
typedef int function(SFMLClass) pf_sfTcpSocket_IsValid;
|
||||
|
||||
static pf_sfSocketTCP_Create sfSocketTCP_Create;
|
||||
static pf_sfSocketTCP_Destroy sfSocketTCP_Destroy;
|
||||
static pf_sfSocketTCP_Connect sfSocketTCP_Connect;
|
||||
static pf_sfSocketTCP_Listen sfSocketTCP_Listen;
|
||||
static pf_sfSocketTCP_Accept sfSocketTCP_Accept;
|
||||
static pf_sfSocketTCP_Send sfSocketTCP_Send;
|
||||
static pf_sfSocketTCP_Receive sfSocketTCP_Receive;
|
||||
static pf_sfSocketTCP_SendPacket sfSocketTCP_SendPacket;
|
||||
static pf_sfSocketTCP_ReceivePacket sfSocketTCP_ReceivePacket;
|
||||
static pf_sfSocketTCP_IsValid sfSocketTCP_IsValid;
|
||||
static pf_sfTcpSocket_Create sfTcpSocket_Create;
|
||||
static pf_sfTcpSocket_Destroy sfTcpSocket_Destroy;
|
||||
static pf_sfTcpSocket_Connect sfTcpSocket_Connect;
|
||||
static pf_sfTcpSocket_Listen sfTcpSocket_Listen;
|
||||
static pf_sfTcpSocket_Accept sfTcpSocket_Accept;
|
||||
static pf_sfTcpSocket_Send sfTcpSocket_Send;
|
||||
static pf_sfTcpSocket_Receive sfTcpSocket_Receive;
|
||||
static pf_sfTcpSocket_SendPacket sfTcpSocket_SendPacket;
|
||||
static pf_sfTcpSocket_ReceivePacket sfTcpSocket_ReceivePacket;
|
||||
static pf_sfTcpSocket_IsValid sfTcpSocket_IsValid;
|
||||
}
|
||||
|
||||
static this()
|
||||
@ -259,15 +259,15 @@ private:
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-network");
|
||||
|
||||
sfSocketTCP_Accept = cast(pf_sfSocketTCP_Accept)dll.getSymbol("sfSocketTCP_Accept");
|
||||
sfSocketTCP_Connect = cast(pf_sfSocketTCP_Connect)dll.getSymbol("sfSocketTCP_Connect");
|
||||
sfSocketTCP_Create = cast(pf_sfSocketTCP_Create)dll.getSymbol("sfSocketTCP_Create");
|
||||
sfSocketTCP_Destroy = cast(pf_sfSocketTCP_Destroy)dll.getSymbol("sfSocketTCP_Destroy");
|
||||
sfSocketTCP_IsValid = cast(pf_sfSocketTCP_IsValid)dll.getSymbol("sfSocketTCP_IsValid");
|
||||
sfSocketTCP_Listen = cast(pf_sfSocketTCP_Listen)dll.getSymbol("sfSocketTCP_Listen");
|
||||
sfSocketTCP_Receive = cast(pf_sfSocketTCP_Receive)dll.getSymbol("sfSocketTCP_Receive");
|
||||
sfSocketTCP_ReceivePacket = cast(pf_sfSocketTCP_ReceivePacket)dll.getSymbol("sfSocketTCP_ReceivePacket");
|
||||
sfSocketTCP_Send = cast(pf_sfSocketTCP_Send)dll.getSymbol("sfSocketTCP_Send");
|
||||
sfSocketTCP_SendPacket = cast(pf_sfSocketTCP_SendPacket)dll.getSymbol("sfSocketTCP_SendPacket");
|
||||
sfTcpSocket_Accept = cast(pf_sfTcpSocket_Accept)dll.getSymbol("sfTcpSocket_Accept");
|
||||
sfTcpSocket_Connect = cast(pf_sfTcpSocket_Connect)dll.getSymbol("sfTcpSocket_Connect");
|
||||
sfTcpSocket_Create = cast(pf_sfTcpSocket_Create)dll.getSymbol("sfTcpSocket_Create");
|
||||
sfTcpSocket_Destroy = cast(pf_sfTcpSocket_Destroy)dll.getSymbol("sfTcpSocket_Destroy");
|
||||
sfTcpSocket_IsValid = cast(pf_sfTcpSocket_IsValid)dll.getSymbol("sfTcpSocket_IsValid");
|
||||
sfTcpSocket_Listen = cast(pf_sfTcpSocket_Listen)dll.getSymbol("sfTcpSocket_Listen");
|
||||
sfTcpSocket_Receive = cast(pf_sfTcpSocket_Receive)dll.getSymbol("sfTcpSocket_Receive");
|
||||
sfTcpSocket_ReceivePacket = cast(pf_sfTcpSocket_ReceivePacket)dll.getSymbol("sfTcpSocket_ReceivePacket");
|
||||
sfTcpSocket_Send = cast(pf_sfTcpSocket_Send)dll.getSymbol("sfTcpSocket_Send");
|
||||
sfTcpSocket_SendPacket = cast(pf_sfTcpSocket_SendPacket)dll.getSymbol("sfTcpSocket_SendPacket");
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
module dsfml.network.socketudp;
|
||||
module dsfml.network.udpsocket;
|
||||
|
||||
import dsfml.network.ipaddress;
|
||||
import dsfml.network.packet;
|
||||
@ -33,23 +33,23 @@ import dsfml.network.socketstatus;
|
||||
import dsfml.system.common;
|
||||
|
||||
/**
|
||||
* SocketUDP wraps a socket using UDP protocol to
|
||||
* UdpSocket wraps a socket using UDP protocol to
|
||||
* send data fastly (but with less safety)
|
||||
*/
|
||||
class SocketUDP : DSFMLObject
|
||||
class UdpSocket : DSFMLObject
|
||||
{
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
this()
|
||||
{
|
||||
super(sfSocketUDP_Create());
|
||||
super(sfUdpSocket_Create());
|
||||
m_intermediatePacket = new Packet();
|
||||
}
|
||||
|
||||
override void dispose()
|
||||
{
|
||||
sfSocketUDP_Destroy(m_ptr);
|
||||
sfUdpSocket_Destroy(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,7 +65,7 @@ class SocketUDP : DSFMLObject
|
||||
bool bind(ushort port)
|
||||
{
|
||||
m_port = port;
|
||||
return cast(bool)sfSocketUDP_Bind(m_ptr, port);
|
||||
return cast(bool)sfUdpSocket_Bind(m_ptr, port);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,7 +77,7 @@ class SocketUDP : DSFMLObject
|
||||
bool unbind()
|
||||
{
|
||||
m_port = 0;
|
||||
return cast(bool)sfSocketUDP_Unbind(m_ptr, m_port);
|
||||
return cast(bool)sfUdpSocket_Unbind(m_ptr, m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,7 +94,7 @@ class SocketUDP : DSFMLObject
|
||||
*/
|
||||
SocketStatus send(byte[] data, IPAddress address, ushort port)
|
||||
{
|
||||
return cast(SocketStatus) sfSocketUDP_Send(m_ptr, data.ptr, data.length, address, port);
|
||||
return cast(SocketStatus) sfUdpSocket_Send(m_ptr, data.ptr, data.length, address, port);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,7 +115,7 @@ class SocketUDP : DSFMLObject
|
||||
*/
|
||||
SocketStatus receive(byte[] data, out size_t sizeReceived, out IPAddress address)
|
||||
{
|
||||
SocketStatus ret = sfSocketUDP_Receive(m_ptr, data.ptr, data.length, &sizeReceived, &address);
|
||||
SocketStatus ret = sfUdpSocket_Receive(m_ptr, data.ptr, data.length, &sizeReceived, &address);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ class SocketUDP : DSFMLObject
|
||||
{
|
||||
byte[] dataArray = packetToSend.onSend();
|
||||
m_intermediatePacket.append(dataArray);
|
||||
SocketStatus stat = cast(SocketStatus)sfSocketUDP_SendPacket(m_ptr, m_intermediatePacket.nativePointer, address, port);
|
||||
SocketStatus stat = cast(SocketStatus)sfUdpSocket_SendPacket(m_ptr, m_intermediatePacket.nativePointer, address, port);
|
||||
m_intermediatePacket.clear();
|
||||
return stat;
|
||||
}
|
||||
@ -154,7 +154,7 @@ class SocketUDP : DSFMLObject
|
||||
*/
|
||||
SocketStatus receive(Packet packetToReceive, out IPAddress address)
|
||||
{
|
||||
SocketStatus ret = sfSocketUDP_ReceivePacket(m_ptr, m_intermediatePacket.nativePointer, &address);
|
||||
SocketStatus ret = sfUdpSocket_ReceivePacket(m_ptr, m_intermediatePacket.nativePointer, &address);
|
||||
packetToReceive.onReceive(m_intermediatePacket.getData);
|
||||
m_intermediatePacket.clear();
|
||||
return ret;
|
||||
@ -171,7 +171,7 @@ class SocketUDP : DSFMLObject
|
||||
*/
|
||||
bool isValid()
|
||||
{
|
||||
return cast(bool)sfSocketUDP_IsValid(m_ptr);
|
||||
return cast(bool)sfUdpSocket_IsValid(m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -200,25 +200,25 @@ private:
|
||||
|
||||
extern (C)
|
||||
{
|
||||
typedef SFMLClass function() pf_sfSocketUDP_Create;
|
||||
typedef void function(SFMLClass) pf_sfSocketUDP_Destroy;
|
||||
typedef int function(SFMLClass, ushort) pf_sfSocketUDP_Bind;
|
||||
typedef int function(SFMLClass, ushort) pf_sfSocketUDP_Unbind;
|
||||
typedef SocketStatus function(SFMLClass, byte*, size_t, IPAddress, ushort) pf_sfSocketUDP_Send;
|
||||
typedef SocketStatus function(SFMLClass, byte*, size_t, size_t*, IPAddress*) pf_sfSocketUDP_Receive;
|
||||
typedef SocketStatus function(SFMLClass, SFMLClass, IPAddress, ushort) pf_sfSocketUDP_SendPacket;
|
||||
typedef SocketStatus function(SFMLClass, SFMLClass, IPAddress*) pf_sfSocketUDP_ReceivePacket;
|
||||
typedef int function(SFMLClass) pf_sfSocketUDP_IsValid;
|
||||
typedef SFMLClass function() pf_sfUdpSocket_Create;
|
||||
typedef void function(SFMLClass) pf_sfUdpSocket_Destroy;
|
||||
typedef int function(SFMLClass, ushort) pf_sfUdpSocket_Bind;
|
||||
typedef int function(SFMLClass, ushort) pf_sfUdpSocket_Unbind;
|
||||
typedef SocketStatus function(SFMLClass, byte*, size_t, IPAddress, ushort) pf_sfUdpSocket_Send;
|
||||
typedef SocketStatus function(SFMLClass, byte*, size_t, size_t*, IPAddress*) pf_sfUdpSocket_Receive;
|
||||
typedef SocketStatus function(SFMLClass, SFMLClass, IPAddress, ushort) pf_sfUdpSocket_SendPacket;
|
||||
typedef SocketStatus function(SFMLClass, SFMLClass, IPAddress*) pf_sfUdpSocket_ReceivePacket;
|
||||
typedef int function(SFMLClass) pf_sfUdpSocket_IsValid;
|
||||
|
||||
static pf_sfSocketUDP_Create sfSocketUDP_Create;
|
||||
static pf_sfSocketUDP_Destroy sfSocketUDP_Destroy;
|
||||
static pf_sfSocketUDP_Bind sfSocketUDP_Bind;
|
||||
static pf_sfSocketUDP_Unbind sfSocketUDP_Unbind;
|
||||
static pf_sfSocketUDP_Send sfSocketUDP_Send;
|
||||
static pf_sfSocketUDP_Receive sfSocketUDP_Receive;
|
||||
static pf_sfSocketUDP_SendPacket sfSocketUDP_SendPacket;
|
||||
static pf_sfSocketUDP_ReceivePacket sfSocketUDP_ReceivePacket;
|
||||
static pf_sfSocketUDP_IsValid sfSocketUDP_IsValid;
|
||||
static pf_sfUdpSocket_Create sfUdpSocket_Create;
|
||||
static pf_sfUdpSocket_Destroy sfUdpSocket_Destroy;
|
||||
static pf_sfUdpSocket_Bind sfUdpSocket_Bind;
|
||||
static pf_sfUdpSocket_Unbind sfUdpSocket_Unbind;
|
||||
static pf_sfUdpSocket_Send sfUdpSocket_Send;
|
||||
static pf_sfUdpSocket_Receive sfUdpSocket_Receive;
|
||||
static pf_sfUdpSocket_SendPacket sfUdpSocket_SendPacket;
|
||||
static pf_sfUdpSocket_ReceivePacket sfUdpSocket_ReceivePacket;
|
||||
static pf_sfUdpSocket_IsValid sfUdpSocket_IsValid;
|
||||
}
|
||||
|
||||
static this()
|
||||
@ -228,14 +228,14 @@ private:
|
||||
else
|
||||
DllLoader dll = DllLoader.load("csfml-network");
|
||||
|
||||
sfSocketUDP_Bind = cast(pf_sfSocketUDP_Bind)dll.getSymbol("sfSocketUDP_Bind");
|
||||
sfSocketUDP_Create = cast(pf_sfSocketUDP_Create)dll.getSymbol("sfSocketUDP_Create");
|
||||
sfSocketUDP_Destroy = cast(pf_sfSocketUDP_Destroy)dll.getSymbol("sfSocketUDP_Destroy");
|
||||
sfSocketUDP_IsValid = cast(pf_sfSocketUDP_IsValid)dll.getSymbol("sfSocketUDP_IsValid");
|
||||
sfSocketUDP_Receive = cast(pf_sfSocketUDP_Receive)dll.getSymbol("sfSocketUDP_Receive");
|
||||
sfSocketUDP_ReceivePacket = cast(pf_sfSocketUDP_ReceivePacket)dll.getSymbol("sfSocketUDP_ReceivePacket");
|
||||
sfSocketUDP_Send = cast(pf_sfSocketUDP_Send)dll.getSymbol("sfSocketUDP_Send");
|
||||
sfSocketUDP_SendPacket = cast(pf_sfSocketUDP_SendPacket)dll.getSymbol("sfSocketUDP_SendPacket");
|
||||
sfSocketUDP_Unbind = cast(pf_sfSocketUDP_Unbind)dll.getSymbol("sfSocketUDP_Unbind");
|
||||
sfUdpSocket_Bind = cast(pf_sfUdpSocket_Bind)dll.getSymbol("sfUdpSocket_Bind");
|
||||
sfUdpSocket_Create = cast(pf_sfUdpSocket_Create)dll.getSymbol("sfUdpSocket_Create");
|
||||
sfUdpSocket_Destroy = cast(pf_sfUdpSocket_Destroy)dll.getSymbol("sfUdpSocket_Destroy");
|
||||
sfUdpSocket_IsValid = cast(pf_sfUdpSocket_IsValid)dll.getSymbol("sfUdpSocket_IsValid");
|
||||
sfUdpSocket_Receive = cast(pf_sfUdpSocket_Receive)dll.getSymbol("sfUdpSocket_Receive");
|
||||
sfUdpSocket_ReceivePacket = cast(pf_sfUdpSocket_ReceivePacket)dll.getSymbol("sfUdpSocket_ReceivePacket");
|
||||
sfUdpSocket_Send = cast(pf_sfUdpSocket_Send)dll.getSymbol("sfUdpSocket_Send");
|
||||
sfUdpSocket_SendPacket = cast(pf_sfUdpSocket_SendPacket)dll.getSymbol("sfUdpSocket_SendPacket");
|
||||
sfUdpSocket_Unbind = cast(pf_sfUdpSocket_Unbind)dll.getSymbol("sfUdpSocket_Unbind");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user