Moved all bindings to the "bindings" sub-directory

Renamed the CSFML directory to c
Renamed the DSFML directory to d
--> bindings must now be updated to match the new organization!

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1630 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2010-11-09 17:13:17 +00:00
parent 0cc5563cac
commit 0e2297af28
417 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,38 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* 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.all;
public import
dsfml.network.ftp,
dsfml.network.http,
dsfml.network.ipaddress,
dsfml.network.packet,
dsfml.network.socketselector,
dsfml.network.socketstatus,
dsfml.network.tcpsocket,
dsfml.network.udpsocket,
dsfml.network.tcplistener ;

View file

@ -0,0 +1,602 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* 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.ftp;
import dsfml.system.common;
import dsfml.system.stringutil;
import dsfml.network.ipaddress;
/**
* Enumeration of transfer mode
*/
enum FtpTransferMode
{
BINARY, ///< Binary mode (file is transfered as a sequence of bytes)
ASCII, ///< Text mode using ASCII encoding
EBCDIC ///< Text mode using EBCDIC encoding
}
/**
* Enumerate all the valid status codes returned in
* a FTP response
*/
enum FtpStatus
{
// 1xx: the requested action is being initiated,
// expect another reply before proceeding with a new command
RESTARTMARKERREPLY = 110, ///< Restart marker reply
SERVICEREADYSOON = 120, ///< Service ready in N minutes
DATACONNECTIONALREADYOPENED = 125, ///< Data connection already opened, transfer starting
OPENINGDATACONNECTION = 150, ///< File status ok, about to open data connection
// 2xx: the requested action has been successfully completed
OK = 200, ///< Command ok
POINTLESSCOMMAND = 202, ///< Command not implemented
SYSTEMSTATUS = 211, ///< System status, or system help reply
DIRECTORYSTATUS = 212, ///< Directory status
FILESTATUS = 213, ///< File status
HELPMESSAGE = 214, ///< Help message
SYSTEMTYPE = 215, ///< NAME system type, where NAME is an official system name from the list in the Assigned Numbers document
SERVICEREADY = 220, ///< Service ready for new user
CLOSINGCONNECTION = 221, ///< Service closing control connection
DATACONNECTIONOPENED = 225, ///< Data connection open, no transfer in progress
CLOSINGDATACONNECTION = 226, ///< Closing data connection, requested file action successful
ENTERINGPASSIVEMODE = 227, ///< Entering passive mode
LOGGEDIN = 230, ///< User logged in, proceed. Logged out if appropriate
FILEACTIONOK = 250, ///< Requested file action ok
DIRECTORYOK = 257, ///< PATHNAME created
// 3xx: the command has been accepted, but the requested action
// is dormant, pending receipt of further information
NEEDPASSWORD = 331, ///< User name ok, need password
NEEDACCOUNTTOLOGIN = 332, ///< Need account for login
NEEDINFORMATION = 350, ///< Requested file action pending further information
// 4xx: the command was not accepted and the requested action did not take place,
// but the error condition is temporary and the action may be requested again
SERVICEUNAVAILABLE = 421, ///< Service not available, closing control connection
DATACONNECTIONUNAVAILABLE = 425, ///< Can't open data connection
TRANSFERABORTED = 426, ///< Connection closed, transfer aborted
FILEACTIONABORTED = 450, ///< Requested file action not taken
LOCALERROR = 451, ///< Requested action aborted, local error in processing
INSUFFICIENTSTORAGESPACE = 452, ///< Requested action not taken; insufficient storage space in system, file unavailable
// 5xx: the command was not accepted and
// the requested action did not take place
COMMANDUNKNOWN = 500, ///< Syntax error, command unrecognized
PARAMETERSUNKNOWN = 501, ///< Syntax error in parameters or arguments
COMMANDNOTIMPLEMENTED = 502, ///< Command not implemented
BADCOMMANDSEQUENCE = 503, ///< Bad sequence of commands
PARAMETERNOTIMPLEMENTED = 504, ///< Command not implemented for that parameter
NOTLOGGEDIN = 530, ///< Not logged in
NEEDACCOUNTTOSTORE = 532, ///< Need account for storing files
FILEUNAVAILABLE = 550, ///< Requested action not taken, file unavailable
PAGETYPEUNKNOWN = 551, ///< Requested action aborted, page type unknown
NOTENOUGHMEMORY = 552, ///< Requested file action aborted, exceeded storage allocation
FILENAMENOTALLOWED = 553, ///< Requested action not taken, file name not allowed
// 10xx: SFML custom codes
INVALIDRESPONSE = 1000, ///< Response is not a valid FTP one
CONNECTIONFAILED = 1001, ///< Connection with server failed
CONNECTIONCLOSED = 1002, ///< Connection with server closed
INVALIDFILE = 1003 ///< Invalid file to upload / download
}
/**
* This class provides methods for manipulating the FTP protocol (described in RFC 959).
* It provides easy access and transfers to remote directories and files on a FTP server.
*/
class Ftp : DSFMLObject
{
/**
* This class wraps a FTP response, which is basically :
* - a status code
* - a message
*/
static class FtpResponse : DSFMLObject
{
override void dispose()
{
sfFtpResponse_Destroy(m_ptr);
}
/**
* Convenience function to check if the response status code
* means a success
*
* Returns:
* True if status is success (code < 400)
*/
bool isOk()
{
return cast(bool)sfFtpResponse_IsOk(m_ptr);
}
/**
* Get the response status code
*
* Returns:
* Status code
*/
FtpStatus getStatus()
{
return sfFtpResponse_GetStatus(m_ptr);
}
/**
* Get the full message contained in the response
*
* Returns:
* The response message
*/
string getMessage()
{
return fromStringz(sfFtpResponse_GetMessage(m_ptr));
}
private:
this(SFMLClass ptr)
{
super(ptr);
}
// External ================================================================
extern (C)
{
typedef void function(SFMLClass) pf_sfFtpResponse_Destroy;
typedef int function(SFMLClass) pf_sfFtpResponse_IsOk;
typedef FtpStatus function(SFMLClass) pf_sfFtpResponse_GetStatus;
typedef ichar* function(SFMLClass) pf_sfFtpResponse_GetMessage;
static pf_sfFtpResponse_Destroy sfFtpResponse_Destroy;
static pf_sfFtpResponse_IsOk sfFtpResponse_IsOk;
static pf_sfFtpResponse_GetStatus sfFtpResponse_GetStatus;
static pf_sfFtpResponse_GetMessage sfFtpResponse_GetMessage;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-network");
sfFtpResponse_Destroy = cast(pf_sfFtpResponse_Destroy)dll.getSymbol("sfFtpResponse_Destroy");
sfFtpResponse_IsOk = cast(pf_sfFtpResponse_IsOk)dll.getSymbol("sfFtpResponse_IsOk");
sfFtpResponse_GetStatus = cast(pf_sfFtpResponse_GetStatus)dll.getSymbol("sfFtpResponse_GetStatus");
sfFtpResponse_GetMessage = cast(pf_sfFtpResponse_GetMessage)dll.getSymbol("sfFtpResponse_GetMessage");
}
}
/**
* Specialization of FTP response returning a directory
*/
static class FtpDirectoryResponse : FtpResponse
{
override void dispose()
{
sfFtpDirectoryResponse_Destroy(m_ptr);
}
/**
* Get the directory returned in the response.
*
* Returns:
* Directory name
*/
string getDirectory()
{
return fromStringz(sfFtpDirectoryResponse_GetDirectory(m_ptr));
}
private:
this(SFMLClass ptr)
{
super(ptr);
}
// External ================================================================
extern (C)
{
typedef void function(SFMLClass) pf_sfFtpDirectoryResponse_Destroy;
typedef ichar* function(SFMLClass) pf_sfFtpDirectoryResponse_GetDirectory;
static pf_sfFtpDirectoryResponse_Destroy sfFtpDirectoryResponse_Destroy;
static pf_sfFtpDirectoryResponse_GetDirectory sfFtpDirectoryResponse_GetDirectory;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-network");
sfFtpDirectoryResponse_Destroy = cast(pf_sfFtpDirectoryResponse_Destroy)dll.getSymbol("sfFtpDirectoryResponse_Destroy");
sfFtpDirectoryResponse_GetDirectory = cast(pf_sfFtpDirectoryResponse_GetDirectory)dll.getSymbol("sfFtpDirectoryResponse_GetDirectory");
}
}
/**
* Specialization of FTP response returning a filename listing.
*/
static class FtpListingResponse : FtpResponse
{
override void dispose()
{
sfFtpListingResponse_Destroy(m_ptr);
}
/**
* Get the number of files in the listing
*
* Returns:
* Total number of files
*/
size_t getCount()
{
return sfFtpListingResponse_GetCount(m_ptr);
}
/**
* Get the index-th filename in the directory
*
* Params:
* index = Index of the filename to get
*
* Returns:
* Filename
*/
string opIndex(size_t index)
{
return fromStringz(sfFtpListingResponse_GetFilename(m_ptr, index));
}
/**
* Foreach implementation
*/
int opApply(int delegate(string) dg)
{
size_t count = getCount();
int result;
for(int i = 0; i < count; i++)
{
result = dg(this[i]);
if (result)
break;
}
return result;
}
private:
this(SFMLClass ptr)
{
super(ptr);
}
// External ================================================================
extern (C)
{
typedef void function(SFMLClass) pf_sfFtpListingResponse_Destroy;
typedef size_t function(SFMLClass) pf_sfFtpListingResponse_GetCount;
typedef ichar* function(SFMLClass, size_t) pf_sfFtpListingResponse_GetFilename;
static pf_sfFtpListingResponse_Destroy sfFtpListingResponse_Destroy;
static pf_sfFtpListingResponse_GetCount sfFtpListingResponse_GetCount;
static pf_sfFtpListingResponse_GetFilename sfFtpListingResponse_GetFilename;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-network");
sfFtpListingResponse_Destroy = cast(pf_sfFtpListingResponse_Destroy)dll.getSymbol("sfFtpListingResponse_Destroy");
sfFtpListingResponse_GetCount = cast(pf_sfFtpListingResponse_GetCount)dll.getSymbol("sfFtpListingResponse_GetCount");
sfFtpListingResponse_GetFilename = cast(pf_sfFtpListingResponse_GetFilename)dll.getSymbol("sfFtpListingResponse_GetFilename");
}
}
/**
* Default constructor
*/
this()
{
super(sfFtp_Create());
}
override void dispose()
{
sfFtp_Destroy(m_ptr);
}
/**
* Connect to the specified FTP server
*
* Params:
* server = FTP server to connect to
* port = Port used for connection (21 by default, standard FTP port)
* timeout = Maximum time to wait, in seconds (0 by default, means no timeout)
*
* Returns:
* Server response to the request
*/
FtpResponse connect(IPAddress server, ushort port = 21, float timeout = 0.f)
{
return new FtpResponse(sfFtp_Connect(m_ptr, server, port, timeout));
}
/**
* Log in using anonymous account
*
* Returns:
* Server response to the request
*/
FtpResponse login()
{
return new FtpResponse(sfFtp_LoginAnonymous(m_ptr));
}
/**
* Log in using a username and a password
*
* Params:
* username = User name
* password = password
*
* Returns:
* Server response to the request
*/
FtpResponse login(string username, string password)
{
return new FtpResponse(sfFtp_Login(m_ptr, toStringz(username), toStringz(password)));
}
/**
* Close the connection with FTP server
*
* Returns:
* Server response to the request
*/
FtpResponse disconnect()
{
return new FtpResponse(sfFtp_Disconnect(m_ptr));
}
/**
* Send a null command to prevent from being disconnected.
*
* Returns:
* Server response to the request
*/
FtpResponse keepAlive()
{
return new FtpResponse(sfFtp_KeepAlive(m_ptr));
}
/**
* Get the current working directory
*
* Returns:
* Server response to the request
*/
FtpDirectoryResponse getWorkingDirectory()
{
return new FtpDirectoryResponse(sfFtp_GetWorkingDirectory(m_ptr));
}
/**
* Get the content of the given directory (subdirectories and files).
*
* Params:
* directory = directory to list (null by default, the current one)
*
* Returns:
* Server response to the request
*/
FtpListingResponse getDirectoryListing(string directory = null)
{
return new FtpListingResponse(sfFtp_GetDirectoryListing(m_ptr, toStringz(directory)));
}
/**
* Change the current working directory
*
* Params:
* directory = New directory, relative to the current one.
*
* Returns:
* Server response to the request
*/
FtpResponse changeDirectory(string directory)
{
return new FtpResponse(sfFtp_ChangeDirectory(m_ptr, toStringz(directory)));
}
/**
* Go to the parent directory of the current one
*
* Returns:
* Server response to the request
*/
FtpResponse parentDirectory()
{
return new FtpResponse(sfFtp_ParentDirectory(m_ptr));
}
/**
* Create a new directory
*
* Params:
* name = name of the directory to create
*
* Returns:
* Server response to the request
*/
FtpResponse createDirectory(string name)
{
return new FtpResponse(sfFtp_CreateDirectory(m_ptr, toStringz(name)));
}
/**
* remove an existing directory
*
* Params:
* name = name of the directory to remove
*
* Returns:
* Server response to the request
*/
FtpResponse deleteDirectory(string name)
{
return new FtpResponse(sfFtp_DeleteDirectory(m_ptr, toStringz(name)));
}
/**
* Rename a file
*
* Params:
* name = file to rename
* newName = new name
*
* Returns:
* Server response to the request
*/
FtpResponse renameFile(string name, string newName)
{
return new FtpResponse(sfFtp_RenameFile(m_ptr, toStringz(name), toStringz(newName)));
}
/**
* Remove an existing file
*
* Params:
* name = file to remove
*
* Returns:
* Server response to the request
*/
FtpResponse deleteFile(string name)
{
return new FtpResponse(sfFtp_DeleteFile(m_ptr, toStringz(name)));
}
/**
* Download a file from the server
*
* Params:
* distantFile = Path of the distant file to download
* destFile = Where to put the file on the local computer
* mode = transfer mode (binary by default)
*
* Returns:
* Server response to the request
*/
FtpResponse download(string distantFile, string destFile, FtpTransferMode mode = FtpTransferMode.BINARY)
{
return new FtpResponse(sfFtp_Download(m_ptr, toStringz(distantFile), toStringz(destFile), mode));
}
/**
* Upload a file to the server
*
* Params:
* localFile = Path of the local file to upload
* destPath = Where to put the file on the server
* mode = transfer mode (binary by default)
* Returns:
* Server response to the request
*/
FtpResponse upload(string localFile, string destFile, FtpTransferMode mode = FtpTransferMode.BINARY)
{
return new FtpResponse(sfFtp_Upload(m_ptr, toStringz(localFile), toStringz(destFile), mode));
}
private:
// External ====================================================================
extern (C)
{
typedef SFMLClass function() pf_sfFtp_Create;
typedef void function(SFMLClass) pf_sfFtp_Destroy;
typedef SFMLClass function(SFMLClass, IPAddress, ushort, float) pf_sfFtp_Connect;
typedef SFMLClass function(SFMLClass) pf_sfFtp_LoginAnonymous;
typedef SFMLClass function(SFMLClass, cchar*, cchar*) pf_sfFtp_Login;
typedef SFMLClass function(SFMLClass) pf_sfFtp_Disconnect;
typedef SFMLClass function(SFMLClass) pf_sfFtp_KeepAlive;
typedef SFMLClass function(SFMLClass) pf_sfFtp_GetWorkingDirectory;
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_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;
typedef SFMLClass function(SFMLClass, cchar*, cchar*, FtpTransferMode) pf_sfFtp_Download;
typedef SFMLClass function(SFMLClass, cchar*, cchar*, FtpTransferMode) pf_sfFtp_Upload;
static pf_sfFtp_Create sfFtp_Create;
static pf_sfFtp_Destroy sfFtp_Destroy;
static pf_sfFtp_Connect sfFtp_Connect;
static pf_sfFtp_LoginAnonymous sfFtp_LoginAnonymous;
static pf_sfFtp_Login sfFtp_Login;
static pf_sfFtp_Disconnect sfFtp_Disconnect;
static pf_sfFtp_KeepAlive sfFtp_KeepAlive;
static pf_sfFtp_GetWorkingDirectory sfFtp_GetWorkingDirectory;
static pf_sfFtp_GetDirectoryListing sfFtp_GetDirectoryListing;
static pf_sfFtp_ChangeDirectory sfFtp_ChangeDirectory;
static pf_sfFtp_ParentDirectory sfFtp_ParentDirectory;
static pf_sfFtp_CreateDirectory sfFtp_CreateDirectory;
static pf_sfFtp_DeleteDirectory sfFtp_DeleteDirectory;
static pf_sfFtp_RenameFile sfFtp_RenameFile;
static pf_sfFtp_DeleteFile sfFtp_DeleteFile;
static pf_sfFtp_Download sfFtp_Download;
static pf_sfFtp_Upload sfFtp_Upload;
}
static this()
{
debug
DllLoader dll = DllLoader.load("csfml-network-d");
else
DllLoader dll = DllLoader.load("csfml-network");
sfFtp_Create = cast(pf_sfFtp_Create)dll.getSymbol("sfFtp_Create");
sfFtp_Destroy = cast(pf_sfFtp_Destroy)dll.getSymbol("sfFtp_Destroy");
sfFtp_Connect = cast(pf_sfFtp_Connect)dll.getSymbol("sfFtp_Connect");
sfFtp_LoginAnonymous = cast(pf_sfFtp_LoginAnonymous)dll.getSymbol("sfFtp_LoginAnonymous");
sfFtp_Login = cast(pf_sfFtp_Login)dll.getSymbol("sfFtp_Login");
sfFtp_Disconnect = cast(pf_sfFtp_Disconnect)dll.getSymbol("sfFtp_Disconnect");
sfFtp_KeepAlive = cast(pf_sfFtp_KeepAlive)dll.getSymbol("sfFtp_KeepAlive");
sfFtp_GetWorkingDirectory = cast(pf_sfFtp_GetWorkingDirectory)dll.getSymbol("sfFtp_GetWorkingDirectory");
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_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");
sfFtp_Download = cast(pf_sfFtp_Download)dll.getSymbol("sfFtp_Download");
sfFtp_Upload = cast(pf_sfFtp_Upload)dll.getSymbol("sfFtp_Upload");
}
}

View file

@ -0,0 +1,398 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* 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.http;
import dsfml.system.stringutil;
import dsfml.system.common;
/**
* HTTP methods enumeration
*/
enum HttpMethod
{
GET, ///< Request in get mode, standard method to retrieve a page
POST, ///< Request in post mode, usually to send data to a page
HEAD ///< Request a page's header only
}
/**
* HTTP response status code
*/
enum HttpStatus
{
// 2xx: success
OK = 200, ///< Most common code returned when operation was successful
CREATED = 201, ///< The resource has successfully been created
ACCEPTED = 202, ///< The request has been accepted, but will be processed later by the server
NOCONTENT = 204, ///< Sent when the server didn't send any data in return
// 3xx: redirection
MULTIPLECHOICES = 300, ///< The requested page can be accessed from several locations
MOVEDPERMANENTLY = 301, ///< The requested page has permanently moved to a new location
MOVEDTEMPORARILY = 302, ///< The requested page has temporarily moved to a new location
NOTMODIFIED = 304, ///< For conditionnal requests, means the requested page hasn't changed and doesn't need to be refreshed
// 4xx: client error
BADREQUEST = 400, ///< The server couldn't understand the request (syntax error)
UNAUTHORIZED = 401, ///< The requested page needs an authentification to be accessed
FORBIDDEN = 403, ///< The requested page cannot be accessed at all, even with authentification
NOTFOUND = 404, ///< The requested page doesn't exist
// 5xx: server error
INTERNALSERVERERROR = 500, ///< The server encountered an unexpected error
NOTIMPLEMENTED = 501, ///< The server doesn't implement a requested feature
BADGATEWAY = 502, ///< The gateway server has received an error from the source server
SERVICENOTAVAILABLE = 503, ///< The server is temporarily unavailable (overloaded, in maintenance, ...)
// 10xx: SFML custom codes
INVALIDRESPONSE = 1000, ///< Response is not a valid HTTP one
CONNECTIONFAILED = 1001 ///< Connection with server failed
}
/**
* This class provides methods for manipulating the HTTP protocol (described in
* RFC 1945).
* It can connect to a website, get files, send requests
*/
class Http : DSFMLObject
{
/**
* Wrapper for a http request, which is basically :
* - a header with a method, a target URI and a set of field/value pairs
* - an optional body (for POST requests)
*/
static class Response : DSFMLObject
{
override void dispose()
{
sfHttpResponse_Destroy(m_ptr);
}
/**
* Get the value of a field
*
* Params:
* field = Name of the field to get (case-insensitive)
* Returns:
* Value of the field, or enpty string if not found
*/
string getField(string field)
{
return fromStringz(sfHttpResponse_GetField(m_ptr, toStringz(field)));
}
/**
* Get the header status code
*
* Returns:
* header status code
*/
HttpStatus getStatus()
{
return sfHttpResponse_GetStatus(m_ptr);
}
/**
* Get the major HTTP version number of the response
*
* Returns:
* Major version number
*/
uint getMajorHTTPVersion()
{
return sfHttpResponse_GetMajorVersion(m_ptr);
}
/**
* Get the minor HTTP version number of the response
*
* Returns:
* Minor version number
*/
uint getMinorHTTPVersion()
{
return sfHttpResponse_GetMinorVersion(m_ptr);
}
/**
* Get the body of the response. The body can contain :
* - the requested page (for GET requests)
* - a response from the server (for POST requests)
* - nothing (for HEAD requests)
* - an error message (in case of an error)
*
* Returns:
* the response body
*/
string getBody()
{
return fromStringz(sfHttpResponse_GetBody(m_ptr));
}
private:
this(SFMLClass ptr)
{
super(ptr);
}
// External ================================================================
extern (C)
{
typedef void function(SFMLClass) pf_sfHttpResponse_Destroy;
typedef ichar* function(SFMLClass, cchar*) pf_sfHttpResponse_GetField;
typedef HttpStatus function(SFMLClass) pf_sfHttpResponse_GetStatus;
typedef uint function(SFMLClass) pf_sfHttpResponse_GetMajorVersion;
typedef uint function(SFMLClass) pf_sfHttpResponse_GetMinorVersion;
typedef ichar* function(SFMLClass) pf_sfHttpResponse_GetBody;
static pf_sfHttpResponse_Destroy sfHttpResponse_Destroy;
static pf_sfHttpResponse_GetField sfHttpResponse_GetField;
static pf_sfHttpResponse_GetStatus sfHttpResponse_GetStatus;
static pf_sfHttpResponse_GetMajorVersion sfHttpResponse_GetMajorVersion;
static pf_sfHttpResponse_GetMinorVersion sfHttpResponse_GetMinorVersion;
static pf_sfHttpResponse_GetBody sfHttpResponse_GetBody;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-network");
sfHttpResponse_Destroy = cast(pf_sfHttpResponse_Destroy)dll.getSymbol("sfHttpResponse_Destroy");
sfHttpResponse_GetField = cast(pf_sfHttpResponse_GetField)dll.getSymbol("sfHttpResponse_GetField");
sfHttpResponse_GetStatus = cast(pf_sfHttpResponse_GetStatus)dll.getSymbol("sfHttpResponse_GetStatus");
sfHttpResponse_GetMajorVersion = cast(pf_sfHttpResponse_GetMajorVersion)dll.getSymbol("sfHttpResponse_GetMajorVersion");
sfHttpResponse_GetMinorVersion = cast(pf_sfHttpResponse_GetMinorVersion)dll.getSymbol("sfHttpResponse_GetMinorVersion");
sfHttpResponse_GetBody = cast(pf_sfHttpResponse_GetBody)dll.getSymbol("sfHttpResponse_GetBody");
}
}
/**
* Wrapper for a HTTP response which is basically :
* - a header with a status code and a set of field/value pairs
* - a body (the content of the requested resource)
*/
static class Request : DSFMLObject
{
/**
* Constructor
*
* Params:
* requestMethod = Method to use for the request (Get by default)
* uri = Target URI ("/" by default -- index page)
* requestBody = Content of the request's body (empty by default)
*/
this(HttpMethod requestMethod = HttpMethod.GET, string uri = "/", string requestBody = "")
{
super(sfHttpRequest_Create());
sfHttpRequest_SetMethod(m_ptr, requestMethod);
sfHttpRequest_SetUri(m_ptr, toStringz(uri));
sfHttpRequest_SetBody(m_ptr, toStringz(requestBody));
}
/**
* Set the value of a field. Field is created if it doesn't exists.
*
* Params:
* field = name of the field to set (case-insensitive)
* value = value of the field
*/
void setField(string field, string value)
{
sfHttpRequest_SetField(m_ptr, toStringz(field), toStringz(value));
}
/**
* Set the request method.
*
* Params:
* requestMethod = Method to use for the request.
*/
void setMethod(HttpMethod requestMethod)
{
sfHttpRequest_SetMethod(m_ptr, requestMethod);
}
/**
* Set the target URI of the request.
*
* Params:
* uri = URI to request, local to the host.
* Returns:
*/
void setUri(string uri)
{
sfHttpRequest_SetUri(m_ptr, toStringz(uri));
}
/**
* Set the HTTP version of the request.
*
* Params:
* major = Major version number
* minor = Minor version number
*/
void setHttpVersion(uint major, uint minor)
{
sfHttpRequest_SetHttpVersion(m_ptr, major, minor);
}
/**
* Set the body of the request. This parameter is optionnal and make sense
* only for POST requests.
*
* Params:
* requestBody = Content of the request body.
*/
void setBody(string requestBody)
{
sfHttpRequest_SetBody(m_ptr, toStringz(requestBody));
}
private:
// External ================================================================
extern (C)
{
typedef SFMLClass function() pf_sfHttpRequest_Create;
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, uint, uint) pf_sfHttpRequest_SetHttpVersion;
typedef void function(SFMLClass, cchar*) pf_sfHttpRequest_SetBody;
static pf_sfHttpRequest_Create sfHttpRequest_Create;
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_SetHttpVersion sfHttpRequest_SetHttpVersion;
static pf_sfHttpRequest_SetBody sfHttpRequest_SetBody;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-network");
sfHttpRequest_Create = cast(pf_sfHttpRequest_Create)dll.getSymbol("sfHttpRequest_Create");
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_SetHttpVersion = cast(pf_sfHttpRequest_SetHttpVersion)dll.getSymbol("sfHttpRequest_SetHttpVersion");
sfHttpRequest_SetBody = cast(pf_sfHttpRequest_SetBody)dll.getSymbol("sfHttpRequest_SetBody");
}
}
/**
* Constructor
*/
this()
{
super(sfHttp_Create());
}
/**
* Constructor
*
* Params:
* host = Web server to connect to
* port = port to use for connection (0 by default -- use the standard port of the protocol)
*/
this(string host, ushort port = 0)
{
super(sfHttp_Create());
sfHttp_SetHost(m_ptr, toStringz(host), port);
}
override void dispose()
{
sfHttp_Destroy(m_ptr);
}
/**
* Set the target host.
*
* Params:
* host = Web server to connect to
* port = port to use for connection (0 by default -- use the standard port of the protocol)
*/
void setHost(string host, ushort port = 0)
{
sfHttp_SetHost(m_ptr, toStringz(host), port);
}
/**
* Send a HTTP request and return the server's response.
* You must be connected to a host before sending requests.
* Any missing mandatory header field will be added with an appropriate value.
*
* Warning : this function waits for the server's response and may
* not return instantly; use a thread if you don't want to block your
* application.
*
* Params:
* req = Request to send
*
* Returns:
* Server's response
*/
Response sendRequest(Request req)
{
return new Response( sfHttp_SendRequest(m_ptr, req.nativePointer) );
}
private:
// External ====================================================================
extern (C)
{
typedef SFMLClass function() pf_sfHttp_Create;
typedef void function(SFMLClass) pf_sfHttp_Destroy;
typedef void function(SFMLClass, cchar*, ushort) pf_sfHttp_SetHost;
typedef SFMLClass function(SFMLClass, SFMLClass) pf_sfHttp_SendRequest;
static pf_sfHttp_Create sfHttp_Create;
static pf_sfHttp_Destroy sfHttp_Destroy;
static pf_sfHttp_SetHost sfHttp_SetHost;
static pf_sfHttp_SendRequest sfHttp_SendRequest;
}
static this()
{
debug
DllLoader dll = DllLoader.load("csfml-network-d");
else
DllLoader dll = DllLoader.load("csfml-network");
sfHttp_Create = cast(pf_sfHttp_Create)dll.getSymbol("sfHttp_Create");
sfHttp_Destroy = cast(pf_sfHttp_Destroy)dll.getSymbol("sfHttp_Destroy");
sfHttp_SetHost = cast(pf_sfHttp_SetHost)dll.getSymbol("sfHttp_SetHost");
sfHttp_SendRequest = cast(pf_sfHttp_SendRequest)dll.getSymbol("sfHttp_SendRequest");
}
}

View file

@ -0,0 +1,148 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* 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.ipaddress;
import dsfml.system.common;
import dsfml.system.stringutil;
/**
* IPAddress provides easy manipulation of IP v4 addresses
*/
struct IPAddress
{
byte[16] Address;
/**
* Construct the address from a string
*
* Params:
* address = IP address ("xxx.xxx.xxx.xxx") or network name
*
*/
static opCall(string address)
{
return sfIpAddress_FromString(toStringz(address));
}
/**
* Construct the address from 4 bytes
*
* Params:
* byte0 = First byte of the address
* byte1 = Second byte of the address
* byte2 = Third byte of the address
* byte3 = Fourth byte of the address
*
*/
static opCall(ubyte byte0, ubyte byte1, ubyte byte2, ubyte byte3)
{
return sfIpAddress_FromBytes(byte0, byte1, byte2, byte3);
}
/**
* Construct the address from a 32 bits integer
*
* Params:
* address = 4 bytes of the address packed into a 32 bits integer
*
*/
static opCall(uint address)
{
return sfIpAddress_FromInteger(address);
}
/**
* Get the empty/invalid address
*
* Returns:
* Empty object that represents invalid addresses
*/
static IPAddress None()
{
return sfIpAddress_None();
}
@property
{
/**
* Get the computer's local IP address (from the LAN point of view)
*
* Returns:
* Local IP address
*
*/
static IPAddress localAddress()
{
return sfIpAddress_GetLocalAddress();
}
/**
* Get the computer's public IP address (from the web point of view).
* The only way to get a public address is to ask it to a
* distant website ; as a consequence, this function may be
* very slow -- use it as few as possible !
*
* Returns:
* Public IP address
*
*/
static IPAddress publicAddress()
{
return sfIpAddress_GetPublicAddress();
}
/**
* Local host address (to connect to the same computer).
*/
static IPAddress localHost()
{
return sfIpAddress_LocalHost();
}
}
const bool opEquals(ref const(IPAddress) other)
{
return Address == other.Address;
}
}
private:
static extern(C)
{
IPAddress function(cchar*) sfIpAddress_FromString;
IPAddress function(ubyte, ubyte, ubyte, ubyte)sfIpAddress_FromBytes;
IPAddress function(uint) sfIpAddress_FromInteger;
IPAddress function() sfIpAddress_None;
IPAddress function() sfIpAddress_GetLocalAddress;
IPAddress function() sfIpAddress_GetPublicAddress;
IPAddress function() sfIpAddress_LocalHost;
}
mixin(loadFromSharedLib2("csfml-network", "sfIpAddress",
"FromBytes", "FromString", "FromInteger", "GetLocalAddress", "GetPublicAddress", "None", "LocalHost"));

View file

@ -0,0 +1,417 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* 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.packet;
import dsfml.system.common;
import dsfml.system.stringutil;
/**
* Packet wraps data to send / to receive through the network
*
* The order of insertion and extraction must be the same.
*
* You can derive from Packet and override onSend and onReceive to do custom operations before send or after reception.
*
* Litterals integer are promoted to int.
* Litterals floating point are promoted to float.
*
* Extraction or insertion can be specified with explicit template.
* Examples:
* ------------------------------------------------------------
* Packet p = new Packet();
*
* int i = 32, j = 42;
* string k = hello;
*
* p.set(i, k, j); //Set the data in the packet
*
* int a, b;
* string c;
* p.get(a, c, b); //Get data from the packet
*
* //...
*
* Packet p = new Packet();
* p.set!(byte)(5); // Litteral are inserted with byte type
* ------------------------------------------------------------
*
* See_Also:
* $(LINK2 http://www.digitalmars.com/d/1.0/lex.html, D litterals Specification) for more informations.
*/
class Packet : DSFMLObject
{
/**
* Default constructor
*
*/
this()
{
super(sfPacket_Create());
}
override void dispose()
{
sfPacket_Destroy(m_ptr);
}
/**
* Append data to the end of the packet.
*
* Params:
* data = Array of data to append
*
*/
void append(byte[] data)
{
if (data !is null)
sfPacket_Append(m_ptr, data.ptr, data.length);
}
/**
* Clear the packet data
*
*/
void clear()
{
sfPacket_Clear(m_ptr);
}
/**
* Get an array to the data contained in the packet
* $(B the returned array may be invalid after you
* append data to the packet)
*
* Returns:
* array of data
*
* Remarks:
* return an array of $(B all) data in the packet.
*
* ----------
* Packet p = new Packet();
*
* string str1 = "Hi";
* string str2 = "Hello";
*
* p.set(str1, str2);
*
* // Retrieve str1 from packet
* string str3;
* p.get(str3);
*
* // Returns an array containing str1 and str2.
* byte[] ptr = p.getData();
* ----------
*/
byte[] getData()
{
if (canRead)
return sfPacket_GetData(m_ptr)[0..getDataSize()];
else
return null;
}
/**
* Get the size of the data contained in the packet
*
* Returns:
* Data size, in bytes
*/
uint getDataSize()
{
return sfPacket_GetDataSize(m_ptr);
}
/**
* Tell if the reading position has reached the end of the packet
*
* Returns:
* true if all data have been read.
*/
bool endOfPacket()
{
return cast(bool)sfPacket_EndOfPacket(m_ptr);
}
/**
* Tell if the packet is valid for reading
*
* Returns:
* True if data can be extracted from the packet
*
*/
bool canRead()
{
return cast(bool)sfPacket_CanRead(m_ptr);
}
/**
* Add new variables to the packet
* Accept (u)byte, (u)short, (u)int, float, double, string and wstring types
*/
Packet set(T...)(T t)
{
foreach (v; t)
internalSet(t);
return this;
}
/**
* Retrieve data from the packet
* Accept (u)byte, (u)short, (u)int, float, double, string and wstring types
*/
Packet get(T...)(ref T t)
{
foreach (v; t)
internalGet(t);
return this;
}
/**
* Called before packet is send
*
* Params:
* size = Variable to fill with the size of the data to send
* Returns:
* Array of byte to send
*/
byte[] onSend()
{
return getData();
}
/**
* Called after a packet has been received
*
* Params:
* data = Array of byte received
*/
void onReceive(byte[] data)
{
append(data);
}
private:
void internalGet(ref bool data)
{
data = cast(bool)sfPacket_ReadInt32(m_ptr);
}
void internalGet(ref byte data)
{
data = sfPacket_ReadInt8(m_ptr);
}
void internalGet(ref ubyte data)
{
data = sfPacket_ReadUint8(m_ptr);
}
void internalGet(ref short data)
{
data = sfPacket_ReadInt16(m_ptr);
}
void internalGet(ref ushort data)
{
data = sfPacket_ReadUint16(m_ptr);
}
void internalGet(ref int data)
{
data = sfPacket_ReadInt32(m_ptr);
}
void internalGet(ref uint data)
{
data = sfPacket_ReadUint32(m_ptr);
}
void internalGet(ref float data)
{
data = sfPacket_ReadFloat(m_ptr);
}
void internalGet(ref double data)
{
data = sfPacket_ReadDouble(m_ptr);
}
void internalGet(ref string data)
{
scope char[] temp = new char[sfPacket_GetDataSize(m_ptr)];
sfPacket_ReadString(m_ptr, temp.ptr);
size_t l = fromStringz(temp.ptr).length;
data = cast(string) temp[0 .. l];
}
void internalGet(ref wstring data)
{
scope wchar[] temp = new wchar[sfPacket_GetDataSize(m_ptr)];
sfPacket_ReadWideString(m_ptr, temp.ptr);
size_t l = fromStringz(temp.ptr).length;
data = cast(wstring) temp[0 .. l];
}
void internalSet(bool data)
{
sfPacket_WriteInt32(m_ptr, cast(int)data);
}
void internalSet(byte data)
{
sfPacket_WriteInt8(m_ptr, data);
}
void internalSet(ubyte data)
{
sfPacket_WriteUint8(m_ptr, data);
}
void internalSet(short data)
{
sfPacket_WriteInt16(m_ptr, data);
}
void internalSet(ushort data)
{
sfPacket_WriteUint16(m_ptr, data);
}
void internalSet(int data)
{
sfPacket_WriteInt32(m_ptr, data);
}
void internalSet(uint data)
{
sfPacket_WriteUint32(m_ptr, data);
}
void internalSet(float data)
{
sfPacket_WriteFloat(m_ptr, data);
}
void internalSet(double data)
{
sfPacket_WriteDouble(m_ptr, data);
}
void internalSet(string data)
{
sfPacket_WriteString(m_ptr, toStringz(data));
}
void internalSet(wstring data)
{
sfPacket_WriteWideString(m_ptr, toStringz(data));
}
// External ====================================================================
extern (C)
{
typedef SFMLClass function() pf_sfPacket_Create;
typedef void function(SFMLClass) pf_sfPacket_Destroy;
typedef void function(SFMLClass, const(void)*, size_t) pf_sfPacket_Append;
typedef void function(SFMLClass) pf_sfPacket_Clear;
typedef byte* function(SFMLClass) pf_sfPacket_GetData;
typedef uint function(SFMLClass) pf_sfPacket_GetDataSize;
typedef int function(SFMLClass) pf_sfPacket_EndOfPacket;
typedef int function(SFMLClass) pf_sfPacket_CanRead;
typedef byte function(SFMLClass) pf_sfPacket_ReadInt8;
typedef ubyte function(SFMLClass) pf_sfPacket_ReadUint8;
typedef short function(SFMLClass) pf_sfPacket_ReadInt16;
typedef ushort function(SFMLClass) pf_sfPacket_ReadUint16;
typedef int function(SFMLClass) pf_sfPacket_ReadInt32;
typedef uint function(SFMLClass) pf_sfPacket_ReadUint32;
typedef float function(SFMLClass) pf_sfPacket_ReadFloat;
typedef double function(SFMLClass) pf_sfPacket_ReadDouble;
typedef void function(SFMLClass, char*) pf_sfPacket_ReadString;
typedef void function(SFMLClass, wchar*) pf_sfPacket_ReadWideString;
typedef void function(SFMLClass, byte) pf_sfPacket_WriteInt8;
typedef void function(SFMLClass, ubyte) pf_sfPacket_WriteUint8;
typedef void function(SFMLClass, short) pf_sfPacket_WriteInt16;
typedef void function(SFMLClass, ushort) pf_sfPacket_WriteUint16;
typedef void function(SFMLClass, int) pf_sfPacket_WriteInt32;
typedef void function(SFMLClass, uint) pf_sfPacket_WriteUint32;
typedef void function(SFMLClass, float) pf_sfPacket_WriteFloat;
typedef void function(SFMLClass, double) pf_sfPacket_WriteDouble;
typedef void function(SFMLClass, cchar*) pf_sfPacket_WriteString;
typedef void function(SFMLClass, cwchar*) pf_sfPacket_WriteWideString;
static pf_sfPacket_Create sfPacket_Create;
static pf_sfPacket_Destroy sfPacket_Destroy;
static pf_sfPacket_Append sfPacket_Append;
static pf_sfPacket_Clear sfPacket_Clear;
static pf_sfPacket_GetData sfPacket_GetData;
static pf_sfPacket_GetDataSize sfPacket_GetDataSize;
static pf_sfPacket_EndOfPacket sfPacket_EndOfPacket;
static pf_sfPacket_CanRead sfPacket_CanRead;
static pf_sfPacket_ReadInt8 sfPacket_ReadInt8;
static pf_sfPacket_ReadUint8 sfPacket_ReadUint8;
static pf_sfPacket_ReadInt16 sfPacket_ReadInt16;
static pf_sfPacket_ReadUint16 sfPacket_ReadUint16;
static pf_sfPacket_ReadInt32 sfPacket_ReadInt32;
static pf_sfPacket_ReadUint32 sfPacket_ReadUint32;
static pf_sfPacket_ReadFloat sfPacket_ReadFloat;
static pf_sfPacket_ReadDouble sfPacket_ReadDouble;
static pf_sfPacket_ReadString sfPacket_ReadString;
static pf_sfPacket_ReadWideString sfPacket_ReadWideString;
static pf_sfPacket_WriteInt8 sfPacket_WriteInt8;
static pf_sfPacket_WriteUint8 sfPacket_WriteUint8;
static pf_sfPacket_WriteInt16 sfPacket_WriteInt16;
static pf_sfPacket_WriteUint16 sfPacket_WriteUint16;
static pf_sfPacket_WriteInt32 sfPacket_WriteInt32;
static pf_sfPacket_WriteUint32 sfPacket_WriteUint32;
static pf_sfPacket_WriteFloat sfPacket_WriteFloat;
static pf_sfPacket_WriteDouble sfPacket_WriteDouble;
static pf_sfPacket_WriteString sfPacket_WriteString;
static pf_sfPacket_WriteWideString sfPacket_WriteWideString;
}
static this()
{
debug
DllLoader dll = DllLoader.load("csfml-network-d");
else
DllLoader dll = DllLoader.load("csfml-network");
sfPacket_Append = cast(pf_sfPacket_Append)dll.getSymbol("sfPacket_Append");
sfPacket_CanRead = cast(pf_sfPacket_CanRead)dll.getSymbol("sfPacket_CanRead");
sfPacket_Clear = cast(pf_sfPacket_Clear)dll.getSymbol("sfPacket_Clear");
sfPacket_Create = cast(pf_sfPacket_Create)dll.getSymbol("sfPacket_Create");
sfPacket_Destroy = cast(pf_sfPacket_Destroy)dll.getSymbol("sfPacket_Destroy");
sfPacket_EndOfPacket = cast(pf_sfPacket_EndOfPacket)dll.getSymbol("sfPacket_EndOfPacket");
sfPacket_GetData = cast(pf_sfPacket_GetData)dll.getSymbol("sfPacket_GetData");
sfPacket_GetDataSize = cast(pf_sfPacket_GetDataSize)dll.getSymbol("sfPacket_GetDataSize");
sfPacket_ReadDouble = cast(pf_sfPacket_ReadDouble)dll.getSymbol("sfPacket_ReadDouble");
sfPacket_ReadFloat = cast(pf_sfPacket_ReadFloat)dll.getSymbol("sfPacket_ReadFloat");
sfPacket_ReadInt16 = cast(pf_sfPacket_ReadInt16)dll.getSymbol("sfPacket_ReadInt16");
sfPacket_ReadInt32 = cast(pf_sfPacket_ReadInt32)dll.getSymbol("sfPacket_ReadInt32");
sfPacket_ReadInt8 = cast(pf_sfPacket_ReadInt8)dll.getSymbol("sfPacket_ReadInt8");
sfPacket_ReadString = cast(pf_sfPacket_ReadString)dll.getSymbol("sfPacket_ReadString");
sfPacket_ReadWideString = cast(pf_sfPacket_ReadWideString)dll.getSymbol("sfPacket_ReadWideString");
sfPacket_ReadUint16 = cast(pf_sfPacket_ReadUint16)dll.getSymbol("sfPacket_ReadUint16");
sfPacket_ReadUint32 = cast(pf_sfPacket_ReadUint32)dll.getSymbol("sfPacket_ReadUint32");
sfPacket_ReadUint8 = cast(pf_sfPacket_ReadUint8)dll.getSymbol("sfPacket_ReadUint8");
sfPacket_WriteDouble = cast(pf_sfPacket_WriteDouble)dll.getSymbol("sfPacket_WriteDouble");
sfPacket_WriteFloat = cast(pf_sfPacket_WriteFloat)dll.getSymbol("sfPacket_WriteFloat");
sfPacket_WriteInt16 = cast(pf_sfPacket_WriteInt16)dll.getSymbol("sfPacket_WriteInt16");
sfPacket_WriteInt32 = cast(pf_sfPacket_WriteInt32)dll.getSymbol("sfPacket_WriteInt32");
sfPacket_WriteInt8 = cast(pf_sfPacket_WriteInt8)dll.getSymbol("sfPacket_WriteInt8");
sfPacket_WriteString = cast(pf_sfPacket_WriteString)dll.getSymbol("sfPacket_WriteString");
sfPacket_WriteWideString = cast(pf_sfPacket_WriteWideString)dll.getSymbol("sfPacket_WriteWideString");
sfPacket_WriteUint16 = cast(pf_sfPacket_WriteUint16)dll.getSymbol("sfPacket_WriteUint16");
sfPacket_WriteUint32 = cast(pf_sfPacket_WriteUint32)dll.getSymbol("sfPacket_WriteUint32");
sfPacket_WriteUint8 = cast(pf_sfPacket_WriteUint8)dll.getSymbol("sfPacket_WriteUint8");
}
}

View file

@ -0,0 +1,153 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* 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.socketselector;
import dsfml.network.tcpsocket;
import dsfml.network.udpsocket;
import dsfml.system.common;
/**
* Multiplexer that allows to read from multiple sockets
*/
class SocketSelector : DSFMLObject
{
/**
* Default constructor
*/
this()
{
super(sfSocketSelector_Create());
}
override void dispose()
{
sfSocketSelector_Destroy(m_ptr);
}
/**
* Add a socket to watch
*
* Params:
* socket = A tcp or udp socket
*/
void add(T socket)
{
if (!(socket.nativePointer in m_watchedSockets))
{
sfSocketSelector_Add(m_ptr, socket.nativePointer);
m_watchedSockets[socket.nativePointer] = socket;
m_numSocketsWatched++;
}
}
/**
* Remove a previously added socket
*
* Params:
* socket = A tcp or udp socket
*/
void remove(T socket)
{
if (socket.nativePointer in m_watchedSockets)
{
sfSocketSelector_Remove(m_ptr, socket.nativePointer);
m_watchedSockets.remove(socket.nativePointer);
m_numSocketsWatched--;
}
}
/**
* Clear all sockets being watched
*/
void clear()
{
sfSocketSelector_Clear(m_ptr);
foreach(key; m_watchedSockets.keys)
m_watchedSockets.remove(key);
m_numSocketsWatched = 0;
}
/**
* Wait and collect sockets which are ready for reading.
* This functions will return either when at least one socket
* is ready, or when the given time is out
*
* Params:
* timeout = Maximum time to wait, in seconds (0 to disable timeout)
*
* Returns:
* Number of sockets ready
*/
uint wait(float timeout = 0.f)
{
return sfSocketSelector_Wait(m_ptr, timeout);
}
/**
* After a call to Wait(), get the Index-th socket which is
* ready for reading. The total number of sockets ready
* is the integer returned by the previous call to Wait()
*
* Params:
* index = Index of the socket to get
*
* Returns:
* The Index-th socket
*/
T GetSocketsReady(uint index)
{
return m_watchedSockets[sfSocketSelector_GetSocketReady(m_ptr, index)];
}
private:
// size_t m_numSocketsWatched;
// T[void*] m_watchedSockets;
// External ====================================================================
static extern(C)
{
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;
}
mixin(loadFromSharedLib2("csfml-network", "sfSocketSelector",
"Create", "Destroy", "AddTcpListener", "AddTcpSocket", "AddUdpSocket", "RemoveTcpListener", "RemoveTcpSocket", "RemoveUdpSocket",
"Clear", "Wait", "IsTcpListenerReady", "IsTcpSocketReady", "IsUdpSocketReady"));
}

View file

@ -0,0 +1,38 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* 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.socketstatus;
/**
* Enumeration of status returned by socket functions
*/
enum SocketStatus
{
DONE, ///
NOTREADY, ///
DISCONNECTED, ///
UNEXPECTEDERROR ///
}

View 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"));
}

View file

@ -0,0 +1,273 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* 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.tcpsocket;
import dsfml.network.ipaddress;
import dsfml.network.packet;
import dsfml.network.socketstatus;
import dsfml.system.common;
/**
* TcpSocket wraps a socket using TCP protocol to send data safely (but a bit slower)
*/
class TcpSocket : DSFMLObject
{
/**
* Default constructor
*/
this()
{
super(sfTcpSocket_Create());
m_intermediatePacket = new Packet();
}
override void dispose()
{
sfTcpSocket_Destroy(m_ptr);
}
/**
* Connect to another computer on a specified port
*
* Params:
* port = Port to use for transfers (warning : ports < 1024 are reserved)
* hostAddress = IP Address of the host to connect to
* timeout = Maximum time to wait in seconds (0 by default : no timeout)
*
* Returns:
* True if operation has been successful
*/
bool connect(ushort port, IPAddress hostAddress, float timeout = 0.f)
{
return cast(bool) !sfTcpSocket_Connect(m_ptr, port, hostAddress, timeout);
}
/**
* Listen to a specified port for incoming data or connections
*
* Params:
* port = Port to listen to
*
* Returns:
* True if operation has been successful
*/
bool listen(ushort port)
{
return cast(bool)sfTcpSocket_Listen(m_ptr, port);
}
/**
* Wait for a connection (must be listening to a port).
* This function is blocking.
*
* Params:
* connected = Socket containing the connection with the connected client
*
* Returns:
* Status code
*/
SocketStatus accept(TcpSocket connected)
{
SFMLClass temp = null;
SocketStatus ret = sfTcpSocket_Accept(m_ptr, &temp, null);
connected.m_ptr = temp;
return ret;
}
/**
* Wait for a connection (must be listening to a port).
* This function is blocking.
*
* Params:
* connected = Socket containing the connection with the connected client
* address = Pointer to an address to fill with client infos
*
* Returns:
* Status code
*/
SocketStatus accept(TcpSocket connected, out IPAddress address)
{
SFMLClass temp = null;
SocketStatus ret = sfTcpSocket_Accept(m_ptr, &temp, &address);
connected.m_ptr = temp;
return ret;
}
/**
* Send an array of bytes to the host (must be connected first)
*
* Params:
* data = array of bytes to send
*
* Returns:
* Status code
*/
SocketStatus send(byte[] data)
in
{
assert(data && data.length);
}
body
{
return cast(SocketStatus)sfTcpSocket_Send(m_ptr, data.ptr, data.length);
}
/**
* Receive an array of bytes from the host (must be connected first).
* This function will block until a connection was accepted
*
* Params:
* data = array to fill (make sure it is big enough)
* sizeReceived = Number of bytes received
*
* Returns:
* Status code
*
* Remarks:
* Assert if data is null or length == 0
*
*/
SocketStatus receive(byte[] data, out size_t sizeReceived)
in
{
assert(data && data.length);
}
body
{
return cast(SocketStatus)sfTcpSocket_Receive(m_ptr, data.ptr, data.length, &sizeReceived);
}
/**
* Send a packet of data to the host (must be connected first)
*
* Params:
* packetToSend = Packet to send
*
* Returns:
* Status code
*
*/
SocketStatus send(Packet packetToSend)
{
byte[] dataArray = packetToSend.onSend();
m_intermediatePacket.append(dataArray);
SocketStatus stat = cast(SocketStatus)sfTcpSocket_SendPacket(m_ptr, m_intermediatePacket.nativePointer);
m_intermediatePacket.clear();
return stat;
}
/**
* Receive a packet from the host (must be connected first).
* This function will block if the socket is blocking
*
* Params:
* packetToReceive = Packet to fill with received data
*
* Returns:
* Status code
*
*/
SocketStatus receive(Packet packetToReceive)
{
SocketStatus stat = cast(SocketStatus)sfTcpSocket_ReceivePacket(m_ptr, m_intermediatePacket.nativePointer);
packetToReceive.onReceive(m_intermediatePacket.getData);
m_intermediatePacket.clear();
return stat;
}
/**
* Check if the socket is in a valid state ; this function
* can be called any time to check if the socket is OK
*
* Returns:
* True if the socket is valid
*
*/
bool isValid()
{
return cast(bool)sfTcpSocket_IsValid(m_ptr);
}
package:
this (SFMLClass ptr)
{
super(ptr);
m_intermediatePacket = new Packet();
}
private:
Packet m_intermediatePacket;
// External ====================================================================
extern (C)
{
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_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()
{
debug
DllLoader dll = DllLoader.load("csfml-network-d");
else
DllLoader dll = DllLoader.load("csfml-network");
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");
}
}

View file

@ -0,0 +1,241 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* 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.udpsocket;
import dsfml.network.ipaddress;
import dsfml.network.packet;
import dsfml.network.socketstatus;
import dsfml.system.common;
/**
* UdpSocket wraps a socket using UDP protocol to
* send data fastly (but with less safety)
*/
class UdpSocket : DSFMLObject
{
/**
* Default constructor
*/
this()
{
super(sfUdpSocket_Create());
m_intermediatePacket = new Packet();
}
override void dispose()
{
sfUdpSocket_Destroy(m_ptr);
}
/**
* Bind the socket to a specific port
*
* Params:
* port = Port to bind the socket to
*
* Returns:
* True if operation has been successful
*
*/
bool bind(ushort port)
{
m_port = port;
return cast(bool)sfUdpSocket_Bind(m_ptr, port);
}
/**
* Unbind the socket from its previous port, if any
*
* Returns: True if operation has been successful
*
*/
bool unbind()
{
m_port = 0;
return cast(bool)sfUdpSocket_Unbind(m_ptr, m_port);
}
/**
* Send an array of bytes
*
* Params:
* data = bytes array to send
* address = Address of the computer to send the packet to
* port = Port to send the data to
*
* Returns:
* Status code
*
*/
SocketStatus send(byte[] data, IPAddress address, ushort port)
{
return cast(SocketStatus) sfUdpSocket_Send(m_ptr, data.ptr, data.length, address, port);
}
/**
* Receive an array of bytes.
* This function is blocking.
*
* Params:
* data = Pointer to a byte array to fill (make sure it is big enough)
* sizeReceived = Number of bytes received
* address = Address of the computer which sent the data
*
* Returns:
* Status code
*
* Remarks:
* Assert if data is null or length == 0
*
*/
SocketStatus receive(byte[] data, out size_t sizeReceived, out IPAddress address)
{
SocketStatus ret = sfUdpSocket_Receive(m_ptr, data.ptr, data.length, &sizeReceived, &address);
return ret;
}
/**
* Send a packet of data
*
* Params:
* packetToSend = Packet to send
* address = Address of the computer to send the packet to
* port = Port to send the data to
*
* Returns:
* Status code
*
*/
SocketStatus send(Packet packetToSend, IPAddress address, ushort port)
{
byte[] dataArray = packetToSend.onSend();
m_intermediatePacket.append(dataArray);
SocketStatus stat = cast(SocketStatus)sfUdpSocket_SendPacket(m_ptr, m_intermediatePacket.nativePointer, address, port);
m_intermediatePacket.clear();
return stat;
}
/**
* Receive a packet.
* This function is blocking.
*
* Params:
* packetToReceive = Packet to fill with received data
* address = Address of the computer which sent the packet
*
* Returns:
* Status code
*
*/
SocketStatus receive(Packet packetToReceive, out IPAddress address)
{
SocketStatus ret = sfUdpSocket_ReceivePacket(m_ptr, m_intermediatePacket.nativePointer, &address);
packetToReceive.onReceive(m_intermediatePacket.getData);
m_intermediatePacket.clear();
return ret;
}
/**
* Check if the socket is in a valid state ; this function
* can be called any time to check if the socket is OK
*
* Returns:
* True if the socket is valid
*
*/
bool isValid()
{
return cast(bool)sfUdpSocket_IsValid(m_ptr);
}
/**
* Get the port the socket is currently bound to
*
* Returns:
* Current port (0 means the socket is not bound)
*/
ushort getPort()
{
return m_port;
}
package:
this (SFMLClass ptr)
{
super(ptr);
m_intermediatePacket = new Packet();
}
private:
Packet m_intermediatePacket;
ushort m_port;
// External ====================================================================
extern (C)
{
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_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()
{
debug
DllLoader dll = DllLoader.load("csfml-network-d");
else
DllLoader dll = DllLoader.load("csfml-network");
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");
}
}