Initial commit -- moved from https://github.com/LaurentGomila/SFML (bindings/c)

This commit is contained in:
Laurent Gomila committed 2011-07-06 22:39:55 +02:00
commit 45d3b05d65
141 files changed
+19124

No files matched your search

+449
View File
@@ -0,0 +1,449 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// 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.
//
////////////////////////////////////////////////////////////
#ifndef SFML_FTP_H
#define SFML_FTP_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.h>
#include <SFML/Network/IpAddress.h>
#include <SFML/Network/Types.h>
////////////////////////////////////////////////////////////
/// Enumerate all the FTP file transfer modes
////////////////////////////////////////////////////////////
enum sfFtpTransferMode
{
sfFtpBinary, ///< Binary mode (file is transfered as a sequence of bytes)
sfFtpAscii, ///< Text mode using ASCII encoding
sfFtpEbcdic ///< Text mode using EBCDIC encoding
};
////////////////////////////////////////////////////////////
/// Enumerate all the valid status codes returned in
/// a FTP response
////////////////////////////////////////////////////////////
enum sfFtpStatus
{
// 1xx: the requested action is being initiated,
// expect another reply before proceeding with a new command
sfFtpRestartMarkerReply = 110, ///< Restart marker reply
sfFtpServiceReadySoon = 120, ///< Service ready in N minutes
sfFtpDataConnectionAlreadyOpened = 125, ///< Data connection already opened, transfer starting
sfFtpOpeningDataConnection = 150, ///< File status ok, about to open data connection
// 2xx: the requested action has been successfully completed
sfFtpOk = 200, ///< Command ok
sfFtpPointlessCommand = 202, ///< Command not implemented
sfFtpSystemStatus = 211, ///< System status, or system help reply
sfFtpDirectoryStatus = 212, ///< Directory status
sfFtpFileStatus = 213, ///< File status
sfFtpHelpMessage = 214, ///< Help message
sfFtpSystemType = 215, ///< NAME system type, where NAME is an official system name from the list in the Assigned Numbers document
sfFtpServiceReady = 220, ///< Service ready for new user
sfFtpClosingConnection = 221, ///< Service closing control connection
sfFtpDataConnectionOpened = 225, ///< Data connection open, no transfer in progress
sfFtpClosingDataConnection = 226, ///< Closing data connection, requested file action successful
sfFtpEnteringPassiveMode = 227, ///< Entering passive mode
sfFtpLoggedIn = 230, ///< User logged in, proceed. Logged out if appropriate
sfFtpFileActionOk = 250, ///< Requested file action ok
sfFtpDirectoryOk = 257, ///< PATHNAME created
// 3xx: the command has been accepted, but the requested action
// is dormant, pending receipt of further information
sfFtpNeedPassword = 331, ///< User name ok, need password
sfFtpNeedAccountToLogIn = 332, ///< Need account for login
sfFtpNeedInformation = 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
sfFtpServiceUnavailable = 421, ///< Service not available, closing control connection
sfFtpDataConnectionUnavailable = 425, ///< Can't open data connection
sfFtpTransferAborted = 426, ///< Connection closed, transfer aborted
sfFtpFileActionAborted = 450, ///< Requested file action not taken
sfFtpLocalError = 451, ///< Requested action aborted, local error in processing
sfFtpInsufficientStorageSpace = 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
sfFtpCommandUnknown = 500, ///< Syntax error, command unrecognized
sfFtpParametersUnknown = 501, ///< Syntax error in parameters or arguments
sfFtpCommandNotImplemented = 502, ///< Command not implemented
sfFtpBadCommandSequence = 503, ///< Bad sequence of commands
sfFtpParameterNotImplemented = 504, ///< Command not implemented for that parameter
sfFtpNotLoggedIn = 530, ///< Not logged in
sfFtpNeedAccountToStore = 532, ///< Need account for storing files
sfFtpFileUnavailable = 550, ///< Requested action not taken, file unavailable
sfFtpPageTypeUnknown = 551, ///< Requested action aborted, page type unknown
sfFtpNotEnoughMemory = 552, ///< Requested file action aborted, exceeded storage allocation
sfFtpFilenameNotAllowed = 553, ///< Requested action not taken, file name not allowed
// 10xx: SFML custom codes
sfFtpInvalidResponse = 1000, ///< Response is not a valid FTP one
sfFtpConnectionFailed = 1001, ///< Connection with server failed
sfFtpConnectionClosed = 1002, ///< Connection with server closed
sfFtpInvalidFile = 1003 ///< Invalid file to upload / download
};
////////////////////////////////////////////////////////////
/// Destroy an existing Ftp listing response
///
/// \param ftpListingResponse : Ftp listing response to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfFtpListingResponse_Destroy(sfFtpListingResponse* ftpListingResponse);
////////////////////////////////////////////////////////////
/// Convenience function to check if the response status code
/// means a success
///
/// \param ftpListingResponse : Ftp listing response
///
/// \return sfTrue if status is success (code < 400)
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfFtpListingResponse_IsOk(const sfFtpListingResponse* ftpListingResponse);
////////////////////////////////////////////////////////////
/// Get the response status code
///
/// \param ftpListingResponse : Ftp listing response
///
/// \return Status code
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpStatus sfFtpListingResponse_GetStatus(const sfFtpListingResponse* ftpListingResponse);
////////////////////////////////////////////////////////////
/// Get the full message contained in the response
///
/// \param ftpListingResponse : Ftp listing response
///
/// \return The response message
///
////////////////////////////////////////////////////////////
CSFML_API const char* sfFtpListingResponse_GetMessage(const sfFtpListingResponse* ftpListingResponse);
////////////////////////////////////////////////////////////
/// Get the number of filenames in the listing
///
/// \param ftpListingResponse : Ftp listing response
///
/// \return Total number of filenames
///
////////////////////////////////////////////////////////////
CSFML_API size_t sfFtpListingResponse_GetCount(const sfFtpListingResponse* ftpListingResponse);
////////////////////////////////////////////////////////////
/// Get the Index-th filename in the directory
///
/// \param ftpListingResponse : Ftp listing response
/// \param index : Index of the filename to get
///
/// \return Index-th filename
///
////////////////////////////////////////////////////////////
CSFML_API const char* sfFtpListingResponse_GetFilename(const sfFtpListingResponse* ftpListingResponse, size_t index);
////////////////////////////////////////////////////////////
/// Destroy an existing Ftp directory response
///
/// \param ftpDirectoryResponse : Ftp directory response to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfFtpDirectoryResponse_Destroy(sfFtpDirectoryResponse* ftpDirectoryResponse);
////////////////////////////////////////////////////////////
/// Convenience function to check if the response status code
/// means a success
///
/// \param ftpDirectoryResponse : Ftp directory response
///
/// \return sfTrue if status is success (code < 400)
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfFtpDirectoryResponse_IsOk(const sfFtpDirectoryResponse* ftpDirectoryResponse);
////////////////////////////////////////////////////////////
/// Get the response status code
///
/// \param ftpDirectoryResponse : Ftp directory response
///
/// \return Status code
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpStatus sfFtpDirectoryResponse_GetStatus(const sfFtpDirectoryResponse* ftpDirectoryResponse);
////////////////////////////////////////////////////////////
/// Get the full message contained in the response
///
/// \param ftpDirectoryResponse : Ftp directory response
///
/// \return The response message
///
////////////////////////////////////////////////////////////
CSFML_API const char* sfFtpDirectoryResponse_GetMessage(const sfFtpDirectoryResponse* ftpDirectoryResponse);
////////////////////////////////////////////////////////////
/// Get the directory returned in the response
///
/// \param ftpDirectoryResponse : Ftp directory response
///
/// \return Directory name
///
////////////////////////////////////////////////////////////
CSFML_API const char* sfFtpDirectoryResponse_GetDirectory(const sfFtpDirectoryResponse* ftpDirectoryResponse);
////////////////////////////////////////////////////////////
/// Destroy an existing Ftp response
///
/// \param ftpResponse : Ftp response to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfFtpResponse_Destroy(sfFtpResponse* ftpResponse);
////////////////////////////////////////////////////////////
/// Convenience function to check if the response status code
/// means a success
///
/// \param ftpResponse : Ftp response
///
/// \return sfTrue if status is success (code < 400)
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfFtpResponse_IsOk(const sfFtpResponse* ftpResponse);
////////////////////////////////////////////////////////////
/// Get the response status code
///
/// \param ftpResponse : Ftp response
///
/// \return Status code
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpStatus sfFtpResponse_GetStatus(const sfFtpResponse* ftpResponse);
////////////////////////////////////////////////////////////
/// Get the full message contained in the response
///
/// \param ftpResponse : Ftp response
///
/// \return The response message
///
////////////////////////////////////////////////////////////
CSFML_API const char* sfFtpResponse_GetMessage(const sfFtpResponse* ftpResponse);
////////////////////////////////////////////////////////////
/// Construct a new Ftp
///
/// \return Pointer to the new Ftp
///
////////////////////////////////////////////////////////////
CSFML_API sfFtp* sfFtp_Create(void);
////////////////////////////////////////////////////////////
/// Destroy an existing Ftp
///
/// \param ftp : Ftp to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfFtp_Destroy(sfFtp* ftp);
////////////////////////////////////////////////////////////
/// Connect to the specified FTP server
///
/// \param ftp : Ftp instance
/// \param server : FTP server to connect to
/// \param port : Port used for connection (21 by default, standard FTP port)
/// \param timeout : Maximum time to wait, in milliseconds (0 to use no timeout)
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_Connect(sfFtp* ftp, sfIpAddress server, unsigned short port, sfUint32 timeout);
////////////////////////////////////////////////////////////
/// Log in using anonymous account
///
/// \param ftp : Ftp instance
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_LoginAnonymous(sfFtp* ftp);
////////////////////////////////////////////////////////////
/// Log in using a username and a password
///
/// \param ftp : Ftp instance
/// \param userName : User name
/// \param password : Password
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_Login(sfFtp* ftp, const char* userName, const char* password);
////////////////////////////////////////////////////////////
/// Close the connection with FTP server
///
/// \param ftp : Ftp instance
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_Disconnect(sfFtp* ftp);
////////////////////////////////////////////////////////////
/// Send a null command just to prevent from being disconnected
///
/// \param ftp : Ftp instance
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_KeepAlive(sfFtp* ftp);
////////////////////////////////////////////////////////////
/// Get the current working directory
///
/// \param ftp : Ftp instance
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpDirectoryResponse* sfFtp_GetWorkingDirectory(sfFtp* ftp);
////////////////////////////////////////////////////////////
/// Get the contents of the given directory
/// (subdirectories and files)
///
/// \param ftp : Ftp instance
/// \param directory : Directory to list ("" by default, the current one)
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpListingResponse* sfFtp_GetDirectoryListing(sfFtp* ftp, const char* directory);
////////////////////////////////////////////////////////////
/// Change the current working directory
///
/// \param ftp : Ftp instance
/// \param directory : New directory, relative to the current one
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_ChangeDirectory(sfFtp* ftp, const char* directory);
////////////////////////////////////////////////////////////
/// Go to the parent directory of the current one
///
/// \param ftp : Ftp instance
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_ParentDirectory(sfFtp* ftp);
////////////////////////////////////////////////////////////
/// Create a new directory
///
/// \param ftp : Ftp instance
/// \param name : Name of the directory to create
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_CreateDirectory(sfFtp* ftp, const char* name);
////////////////////////////////////////////////////////////
/// Remove an existing directory
///
/// \param ftp : Ftp instance
/// \param name : Name of the directory to remove
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_DeleteDirectory(sfFtp* ftp, const char* name);
////////////////////////////////////////////////////////////
/// Rename a file
///
/// \param ftp : Ftp instance
/// \param file : File to rename
/// \param newName : New name
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_RenameFile(sfFtp* ftp, const char* file, const char* newName);
////////////////////////////////////////////////////////////
/// Remove an existing file
///
/// \param ftp : Ftp instance
/// \param name : File to remove
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_DeleteFile(sfFtp* ftp, const char* name);
////////////////////////////////////////////////////////////
/// Download a file from the server
///
/// \param ftp : Ftp instance
/// \param distantFile : Path of the distant file to download
/// \param destPath : Where to put to file on the local computer
/// \param mode : Transfer mode (binary by default)
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_Download(sfFtp* ftp, const char* distantFile, const char* destPath, sfFtpTransferMode mode);
////////////////////////////////////////////////////////////
/// Upload a file to the server
///
/// \param ftp : Ftp instance
/// \param localFile : Path of the local file to upload
/// \param destPath : Where to put to file on the server
/// \param mode : Transfer mode (binary by default)
///
/// \return Server response to the request
///
////////////////////////////////////////////////////////////
CSFML_API sfFtpResponse* sfFtp_Upload(sfFtp* ftp, const char* localFile, const char* destPath, sfFtpTransferMode mode);
#endif // SFML_FTP_H
+257
View File
@@ -0,0 +1,257 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// 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.
//
////////////////////////////////////////////////////////////
#ifndef SFML_HTTP_H
#define SFML_HTTP_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.h>
#include <SFML/Network/Types.h>
////////////////////////////////////////////////////////////
/// Enumerate the available HTTP methods for a request
////////////////////////////////////////////////////////////
enum sfHttpMethod
{
sfHttpGet, ///< Request in get mode, standard method to retrieve a page
sfHttpPost, ///< Request in post mode, usually to send data to a page
sfHttpHead ///< Request a page's header only
};
////////////////////////////////////////////////////////////
/// Enumerate all the valid status codes returned in
/// a HTTP response
////////////////////////////////////////////////////////////
enum sfHttpStatus
{
// 2xx: success
sfHttpOk = 200, ///< Most common code returned when operation was successful
sfHttpCreated = 201, ///< The resource has successfully been created
sfHttpAccepted = 202, ///< The request has been accepted, but will be processed later by the server
sfHttpNoContent = 204, ///< Sent when the server didn't send any data in return
// 3xx: redirection
sfHttpMultipleChoices = 300, ///< The requested page can be accessed from several locations
sfHttpMovedPermanently = 301, ///< The requested page has permanently moved to a new location
sfHttpMovedTemporarily = 302, ///< The requested page has temporarily moved to a new location
sfHttpNotModified = 304, ///< For conditionnal requests, means the requested page hasn't changed and doesn't need to be refreshed
// 4xx: client error
sfHttpBadRequest = 400, ///< The server couldn't understand the request (syntax error)
sfHttpUnauthorized = 401, ///< The requested page needs an authentification to be accessed
sfHttpForbidden = 403, ///< The requested page cannot be accessed at all, even with authentification
sfHttpNotFound = 404, ///< The requested page doesn't exist
// 5xx: server error
sfHttpInternalServerError = 500, ///< The server encountered an unexpected error
sfHttpNotImplemented = 501, ///< The server doesn't implement a requested feature
sfHttpBadGateway = 502, ///< The gateway server has received an error from the source server
sfHttpServiceNotAvailable = 503, ///< The server is temporarily unavailable (overloaded, in maintenance, ...)
// 10xx: SFML custom codes
sfHttpInvalidResponse = 1000, ///< Response is not a valid HTTP one
sfHttpConnectionFailed = 1001 ///< Connection with server failed
};
////////////////////////////////////////////////////////////
/// Construct a new Http request
///
/// \return Pointer to the new Http request
///
////////////////////////////////////////////////////////////
CSFML_API sfHttpRequest* sfHttpRequest_Create(void);
////////////////////////////////////////////////////////////
/// Destroy an existing Http request
///
/// \param httpRequest : Http request to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttpRequest_Destroy(sfHttpRequest* httpRequest);
////////////////////////////////////////////////////////////
/// Set the value of a field; the field is added if it doesn't exist
///
/// \param httpRequest : Http request to modify
/// \param field : Name of the field to set (case-insensitive)
/// \param value : Value of the field
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttpRequest_SetField(sfHttpRequest* httpRequest, const char* field, const char* value);
////////////////////////////////////////////////////////////
/// Set the request method.
/// This parameter is sfHttpGet by default
///
/// \param httpRequest : Http request to modify
/// \param method : Method to use for the request
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttpRequest_SetMethod(sfHttpRequest* httpRequest, sfHttpMethod method);
////////////////////////////////////////////////////////////
/// Set the target URI of the request.
/// This parameter is "/" by default
///
/// \param httpRequest : Http request to modify
/// \param URI : URI to request, local to the host
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttpRequest_SetUri(sfHttpRequest* httpRequest, const char* uri);
////////////////////////////////////////////////////////////
/// Set the HTTP version of the request.
/// This parameter is 1.0 by default
///
/// \param httpRequest : Http request to modify
/// \param major : Major version number
/// \param minor : Minor version number
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttpRequest_SetHttpVersion(sfHttpRequest* httpRequest, unsigned int major, unsigned int minor);
////////////////////////////////////////////////////////////
/// Set the body of the request. This parameter is optional and
/// makes sense only for POST requests.
/// This parameter is empty by default
///
/// \param httpRequest : Http request to modify
/// \param body : Content of the request body
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttpRequest_SetBody(sfHttpRequest* httpRequest, const char* body);
////////////////////////////////////////////////////////////
/// Destroy an existing Http response
///
/// \param httpResponse : Http response to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttpResponse_Destroy(sfHttpResponse* httpResponse);
////////////////////////////////////////////////////////////
/// Get the value of a field; returns NULL if the field doesn't exist
///
/// \param httpResponse : Http response
/// \param field : Field to get
///
/// \return Value of the field (NULL if it doesn't exist)
///
////////////////////////////////////////////////////////////
CSFML_API const char* sfHttpResponse_GetField(const sfHttpResponse* httpResponse, const char* field);
////////////////////////////////////////////////////////////
/// Get the status of a response
///
/// \param httpResponse : Http response
///
/// \return Status of the response
///
////////////////////////////////////////////////////////////
CSFML_API sfHttpStatus sfHttpResponse_GetStatus(const sfHttpResponse* httpResponse);
////////////////////////////////////////////////////////////
/// Get the major HTTP version of a response
///
/// \param httpResponse : Http response
///
/// \return HTTP major version of the response
///
////////////////////////////////////////////////////////////
CSFML_API unsigned int sfHttpResponse_GetMajorVersion(const sfHttpResponse* httpResponse);
////////////////////////////////////////////////////////////
/// Get the minor HTTP version of a response
///
/// \param httpResponse : Http response
///
/// \return HTTP minor version of the response
///
////////////////////////////////////////////////////////////
CSFML_API unsigned int sfHttpResponse_GetMinorVersion(const sfHttpResponse* httpResponse);
////////////////////////////////////////////////////////////
/// 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)
///
/// \param httpResponse : Http response
///
/// \return Body of the response (empty string if no body)
///
////////////////////////////////////////////////////////////
CSFML_API const char* sfHttpResponse_GetBody(const sfHttpResponse* httpResponse);
////////////////////////////////////////////////////////////
/// Construct a new Http object
///
/// \return Pointer to the new Http
///
////////////////////////////////////////////////////////////
CSFML_API sfHttp* sfHttp_Create(void);
////////////////////////////////////////////////////////////
/// Destroy an existing Http object
///
/// \param Http : Http to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttp_Destroy(sfHttp* http);
////////////////////////////////////////////////////////////
/// Set the target host of a Http server
///
/// \param http : Http object
/// \param host : Web server to connect to
/// \param port : Port to use for connection (0 to use the standard port of the protocol used)
///
////////////////////////////////////////////////////////////
CSFML_API void sfHttp_SetHost(sfHttp* http, const char* host, unsigned short 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.
///
/// \param http : Http object
/// \param request : Request to send
/// \param timeout : Maximum time to wait, in milliseconds (0 to use no timeout)
///
/// \return Server's response, or NULL if request is invalid
///
////////////////////////////////////////////////////////////
CSFML_API sfHttpResponse* sfHttp_SendRequest(sfHttp* http, const sfHttpRequest* request, sfUint32 timeout);
#endif // SFML_HTTP_H
+131
View File
@@ -0,0 +1,131 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// 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.
//
////////////////////////////////////////////////////////////
#ifndef SFML_IPADDRESS_H
#define SFML_IPADDRESS_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.h>
////////////////////////////////////////////////////////////
/// sfIpAddress provides easy manipulation of IP v4 addresses
////////////////////////////////////////////////////////////
typedef struct
{
char Address[16];
} sfIpAddress;
////////////////////////////////////////////////////////////
/// Construct an address from a string
///
/// \param string : IP address ("xxx.xxx.xxx.xxx") or network name
///
/// \return Resulting address
///
////////////////////////////////////////////////////////////
CSFML_API sfIpAddress sfIpAddress_FromString(const char* string);
////////////////////////////////////////////////////////////
/// Construct an address from 4 bytes
///
/// \param byte0 : First byte of the address
/// \param byte1 : Second byte of the address
/// \param byte2 : Third byte of the address
/// \param byte3 : Fourth byte of the address
///
/// \return Resulting address
///
////////////////////////////////////////////////////////////
CSFML_API sfIpAddress sfIpAddress_FromBytes(sfUint8 byte0, sfUint8 byte1, sfUint8 byte2, sfUint8 byte3);
////////////////////////////////////////////////////////////
/// Construct the address from a 32-bits integer
///
/// \param address : 4 bytes of the address packed into a 32-bits integer
///
////////////////////////////////////////////////////////////
CSFML_API sfIpAddress sfIpAddress_FromInteger(sfUint32 address);
////////////////////////////////////////////////////////////
/// Get a string representation of an address
///
/// \param address : Address to convert
/// \param string : Char array to fill (size must be >= 16)
///
////////////////////////////////////////////////////////////
CSFML_API void sfIpAddress_ToString(sfIpAddress address, char* string);
////////////////////////////////////////////////////////////
/// Get an integer representation of the address
///
/// \param address : Address to convert
///
/// \return 32-bits integer containing the 4 bytes of the address, in system endianness
///
////////////////////////////////////////////////////////////
CSFML_API sfUint32 sfIpAddress_ToInteger(sfIpAddress address);
////////////////////////////////////////////////////////////
/// Get the computer's local IP address (from the LAN point of view)
///
/// \return Local IP address
///
////////////////////////////////////////////////////////////
CSFML_API sfIpAddress sfIpAddress_GetLocalAddress(void);
////////////////////////////////////////////////////////////
/// 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 !
///
/// \param timeout : Maximum time to wait, in milliseconds (use 0 for no timeout)
///
/// \return Public IP address
///
////////////////////////////////////////////////////////////
CSFML_API sfIpAddress sfIpAddress_GetPublicAddress(sfUint32 timeout);
////////////////////////////////////////////////////////////
/// Get the computer's loopback address
///
/// \return Local host IP address (127.0.0.1, or "localhost")
///
////////////////////////////////////////////////////////////
CSFML_API sfIpAddress sfIpAddress_LocalHost(void);
////////////////////////////////////////////////////////////
/// Get the empty/invalid address
///
/// \return Empty object that represents invalid addresses
///
////////////////////////////////////////////////////////////
CSFML_API sfIpAddress sfIpAddress_None(void);
#endif // SFML_IPADDRESS_H
+158
View File
@@ -0,0 +1,158 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// 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.
//
////////////////////////////////////////////////////////////
#ifndef SFML_PACKET_H
#define SFML_PACKET_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.h>
#include <SFML/Network/Types.h>
////////////////////////////////////////////////////////////
/// Create a new empty packet
///
/// \return A new sfPacket object
///
////////////////////////////////////////////////////////////
CSFML_API sfPacket* sfPacket_Create(void);
////////////////////////////////////////////////////////////
/// Copy an existing packet
///
/// \param packet : Packet to copy
///
/// \return Copied object
///
////////////////////////////////////////////////////////////
CSFML_API sfPacket* sfPacket_Copy(sfPacket* packet);
////////////////////////////////////////////////////////////
/// Destroy an existing packet
///
/// \param packet : Packet to delete
///
////////////////////////////////////////////////////////////
CSFML_API void sfPacket_Destroy(sfPacket* packet);
////////////////////////////////////////////////////////////
/// Append data to the end of a packet
///
/// \param packet : Packet to fill
/// \param data : Pointer to the bytes to append
/// \param sizeInBytes : Number of bytes to append
///
////////////////////////////////////////////////////////////
CSFML_API void sfPacket_Append(sfPacket* packet, const void* data, size_t sizeInBytes);
////////////////////////////////////////////////////////////
/// Clear all the data of a packet
///
/// \param packet : Packet to clear
///
///////////////////////////////////////////////////////////
CSFML_API void sfPacket_Clear(sfPacket* packet);
////////////////////////////////////////////////////////////
/// Get a pointer to the data contained in a packet
/// Warning : the returned pointer may be invalid after you
/// append data to the packet
///
/// \param packet : Packet to get data from
///
/// \return Pointer to the data
///
////////////////////////////////////////////////////////////
CSFML_API const char* sfPacket_GetData(const sfPacket* packet);
////////////////////////////////////////////////////////////
/// Get the size of the data contained in a packet
///
/// \param packet : Packet to get data size from
///
/// \return Data size, in bytes
///
////////////////////////////////////////////////////////////
CSFML_API size_t sfPacket_GetDataSize(const sfPacket* packet);
////////////////////////////////////////////////////////////
/// Tell if the reading position has reached the end of the packet
///
/// \param packet : Packet to check
///
/// \return sfTrue if all data have been read into the packet
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfPacket_EndOfPacket(const sfPacket* packet);
////////////////////////////////////////////////////////////
/// Return the validity of packet
///
/// \param packet : Packet to check
///
/// \return sfTrue if last data extraction from packet was successful
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfPacket_CanRead(const sfPacket* packet);
////////////////////////////////////////////////////////////
/// Functions to extract data from a packet
///
/// \param packet : Packet to read
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfPacket_ReadBool(sfPacket* packet);
CSFML_API sfInt8 sfPacket_ReadInt8(sfPacket* packet);
CSFML_API sfUint8 sfPacket_ReadUint8(sfPacket* packet);
CSFML_API sfInt16 sfPacket_ReadInt16(sfPacket* packet);
CSFML_API sfUint16 sfPacket_ReadUint16(sfPacket* packet);
CSFML_API sfInt32 sfPacket_ReadInt32(sfPacket* packet);
CSFML_API sfUint32 sfPacket_ReadUint32(sfPacket* packet);
CSFML_API float sfPacket_ReadFloat(sfPacket* packet);
CSFML_API double sfPacket_ReadDouble(sfPacket* packet);
CSFML_API void sfPacket_ReadString(sfPacket* packet, char* string);
CSFML_API void sfPacket_ReadWideString(sfPacket* packet, wchar_t* string);
////////////////////////////////////////////////////////////
/// Functions to insert data into a packet
///
/// \param packet : Packet to write
///
////////////////////////////////////////////////////////////
CSFML_API void sfPacket_WriteBool(sfPacket* packet, sfBool);
CSFML_API void sfPacket_WriteInt8(sfPacket* packet, sfInt8);
CSFML_API void sfPacket_WriteUint8(sfPacket* packet, sfUint8);
CSFML_API void sfPacket_WriteInt16(sfPacket* packet, sfInt16);
CSFML_API void sfPacket_WriteUint16(sfPacket* packet, sfUint16);
CSFML_API void sfPacket_WriteInt32(sfPacket* packet, sfInt32);
CSFML_API void sfPacket_WriteUint32(sfPacket* packet, sfUint32);
CSFML_API void sfPacket_WriteFloat(sfPacket* packet, float);
CSFML_API void sfPacket_WriteDouble(sfPacket* packet, double);
CSFML_API void sfPacket_WriteString(sfPacket* packet, const char* string);
CSFML_API void sfPacket_WriteWideString(sfPacket* packet, const wchar_t* string);
#endif // SFML_PACKET_H
+118
View File
@@ -0,0 +1,118 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// 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.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOCKETSELECTOR_H
#define SFML_SOCKETSELECTOR_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.h>
#include <SFML/Network/Types.h>
////////////////////////////////////////////////////////////
/// Create a new selector
///
/// \return A new sfSelector object
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketSelector* sfSocketSelector_Create(void);
////////////////////////////////////////////////////////////
/// Copy an existing selector
///
/// \param selector : Selector to copy
///
/// \return Copied object
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketSelector* sfSocketSelector_Copy(sfSocketSelector* selector);
////////////////////////////////////////////////////////////
/// Destroy an existing selector
///
/// \param selector : Selector to delete
///
////////////////////////////////////////////////////////////
CSFML_API void sfSocketSelector_Destroy(sfSocketSelector* selector);
////////////////////////////////////////////////////////////
/// Add a socket to watch to a selector
///
/// \param selector : Selector to add the socket to
/// \param socket : Socket to add
///
////////////////////////////////////////////////////////////
CSFML_API void sfSocketSelector_AddTcpListener(sfSocketSelector* selector, sfTcpListener* socket);
CSFML_API void sfSocketSelector_AddTcpSocket(sfSocketSelector* selector, sfTcpSocket* socket);
CSFML_API void sfSocketSelector_AddUdpSocket(sfSocketSelector* selector, sfUdpSocket* socket);
////////////////////////////////////////////////////////////
/// Remove a socket from a selector
///
/// \param selector : Selector to remove the socket from
/// \param socket : Socket to remove
///
////////////////////////////////////////////////////////////
CSFML_API void sfSocketSelector_RemoveTcpListener(sfSocketSelector* selector, sfTcpListener* socket);
CSFML_API void sfSocketSelector_RemoveTcpSocket(sfSocketSelector* selector, sfTcpSocket* socket);
CSFML_API void sfSocketSelector_RemoveUdpSocket(sfSocketSelector* selector, sfUdpSocket* socket);
////////////////////////////////////////////////////////////
/// Remove all sockets from a selector
///
/// \param selector : Selector to remove the socket from
///
////////////////////////////////////////////////////////////
CSFML_API void sfSocketSelector_Clear(sfSocketSelector* selector);
////////////////////////////////////////////////////////////
/// 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 timeout is over
///
/// \param selector : Selector to check
/// \param timeout : Maximum time to wait, in milliseconds (0 to disable timeout)
///
/// \return sfTrue if there are sockets ready, sfFalse otherwise
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfSocketSelector_Wait(sfSocketSelector* selector, sfUint32 timeout);
////////////////////////////////////////////////////////////
/// Test a socket to know if it is ready to receive data
///
/// \param selector : Selector to check
/// \param socket : Socket to test
///
/// \return sfTrue if the socket is ready to receive data
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfSocketSelector_IsTcpListenerReady(const sfSocketSelector* selector, sfTcpListener* socket);
CSFML_API sfBool sfSocketSelector_IsTcpSocketReady(const sfSocketSelector* selector, sfTcpSocket* socket);
CSFML_API sfBool sfSocketSelector_IsUdpSocketReady(const sfSocketSelector* selector, sfUdpSocket* socket);
#endif // SFML_SOCKETSELECTOR_H
+43
View File
@@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// 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.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOCKETSTATUS_H
#define SFML_SOCKETSTATUS_H
////////////////////////////////////////////////////////////
/// Define the status that can be returned by the socket
/// functions
////////////////////////////////////////////////////////////
typedef enum
{
sfSocketDone,
sfSocketNotReady,
sfSocketDisconnected,
sfSocketError
} sfSocketStatus;
#endif // SFML_SOCKETSTATUS_H
+97
View File
@@ -0,0 +1,97 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// 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.
//
////////////////////////////////////////////////////////////
#ifndef SFML_TCPLISTENER_H
#define SFML_TCPLISTENER_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.h>
#include <SFML/Network/SocketStatus.h>
#include <SFML/Network/Types.h>
////////////////////////////////////////////////////////////
/// Construct a new TCP socket
///
/// \return Pointer to the new socket
///
////////////////////////////////////////////////////////////
CSFML_API sfTcpListener* sfTcpListener_Create(void);
////////////////////////////////////////////////////////////
/// Destroy an existing TCP socket
///
/// \param socket : Socket to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfTcpListener_Destroy(sfTcpListener* socket);
////////////////////////////////////////////////////////////
/// Change the blocking state of a TCP socket.
/// The default behaviour of a socket is blocking
///
/// \param socket : Socket to modify
/// \param blocking : Pass sfTrue to set the socket as blocking, or sfFalse for non-blocking
///
////////////////////////////////////////////////////////////
CSFML_API void sfTcpListener_SetBlocking(sfTcpListener* socket, sfBool blocking);
////////////////////////////////////////////////////////////
/// Get the blocking state of the socket
///
/// \param socket : Socket to read
///
/// \Return sfTrue if the socket is blocking, sfFalse otherwise
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfTcpListener_IsBlocking(const sfTcpListener* socket);
////////////////////////////////////////////////////////////
/// Listen to a specified port for incoming data or connections
///
/// \param socket : Socket to use for listening
/// \param port : Port to listen to
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfTcpListener_Listen(sfTcpListener* socket, unsigned short port);
////////////////////////////////////////////////////////////
/// Wait for a connection (must be listening to a port).
/// This function is blocking, ie. it won't return before
/// a connection has been accepted
///
/// \param socket : Socket to use for accepting
/// \param connected : Pointer to a socket pointer that will be filled with the connected client
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfTcpListener_Accept(sfTcpListener* socket, sfTcpSocket** connected);
#endif // SFML_TCPLISTENER_H
+172
View File
@@ -0,0 +1,172 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// 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.
//
////////////////////////////////////////////////////////////
#ifndef SFML_TCPSOCKET_H
#define SFML_TCPSOCKET_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.h>
#include <SFML/Network/IpAddress.h>
#include <SFML/Network/SocketStatus.h>
#include <SFML/Network/Types.h>
////////////////////////////////////////////////////////////
/// Construct a new TCP socket
///
/// \return Pointer to the new socket
///
////////////////////////////////////////////////////////////
CSFML_API sfTcpSocket* sfTcpSocket_Create(void);
////////////////////////////////////////////////////////////
/// Destroy an existing TCP socket
///
/// \param socket : Socket to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfTcpSocket_Destroy(sfTcpSocket* socket);
////////////////////////////////////////////////////////////
/// Change the blocking state of a TCP socket.
/// The default behaviour of a socket is blocking
///
/// \param socket : Socket to modify
/// \param blocking : Pass sfTrue to set the socket as blocking, or false for non-blocking
///
////////////////////////////////////////////////////////////
CSFML_API void sfTcpSocket_SetBlocking(sfTcpSocket* socket, sfBool blocking);
////////////////////////////////////////////////////////////
/// Get the blocking state of the socket
///
/// \param socket : Socket to read
///
/// \Return sfTrue if the socket is blocking, sfFalse otherwise
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfTcpSocket_IsBlocking(const sfTcpSocket* socket);
////////////////////////////////////////////////////////////
/// Get the port to which a socket is bound locally
///
/// \param socket : Socket to read
///
/// \return Port to which the socket is bound
///
////////////////////////////////////////////////////////////
CSFML_API unsigned short sfTcpSocket_GetLocalPort(const sfTcpSocket* socket);
////////////////////////////////////////////////////////////
/// Get the address of the connected peer of a socket
///
/// \param socket : Socket to read
///
/// \return Address of the remote peer
///
////////////////////////////////////////////////////////////
CSFML_API sfIpAddress sfTcpSocket_GetRemoteAddress(const sfTcpSocket* socket);
////////////////////////////////////////////////////////////
/// Get the port of the connected peer to which a socket is connected
///
/// \param socket : Socket to read
///
/// \return Remote port to which the socket is connected
///
////////////////////////////////////////////////////////////
CSFML_API unsigned short sfTcpSocket_GetRemotePort(const sfTcpSocket* socket);
////////////////////////////////////////////////////////////
/// Connect a TCP socket to another computer on a specified port
///
/// \param socket : Socket to connect
/// \param host : IP Address of the host to connect to
/// \param port : Port to use for transfers (warning : ports < 1024 are reserved)
/// \param timeout : Maximum time to wait, in milliseconds (0 to use no timeout)
///
/// \return sfTrue if operation has been successful
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfTcpSocket_Connect(sfTcpSocket* socket, sfIpAddress host, unsigned short port, sfUint32 timeout);
////////////////////////////////////////////////////////////
/// Disconnect a connect from its remote peer
///
/// \param socket : Socket to disconnect
///
////////////////////////////////////////////////////////////
CSFML_API void sfTcpSocket_Disconnect(sfTcpSocket* socket);
////////////////////////////////////////////////////////////
/// Send an array of bytes to the host (must be connected first)
///
/// \param socket : Socket to use for sending
/// \param data : Pointer to the bytes to send
/// \param size : Number of bytes to send
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfTcpSocket_Send(sfTcpSocket* socket, const char* data, size_t size);
////////////////////////////////////////////////////////////
/// Receive an array of bytes from the host (must be connected first)
///
/// \param socket : Socket to use for receiving
/// \param data : Pointer to a byte array to fill (make sure it is big enough)
/// \param maxSize : Maximum number of bytes to read
/// \param sizeReceived : Number of bytes received
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfTcpSocket_Receive(sfTcpSocket* socket, char* data, size_t maxSize, size_t* sizeReceived);
////////////////////////////////////////////////////////////
/// Send a packet of data to the host (must be connected first)
///
/// \param socket : Socket to use for sending
/// \param packet : Packet to send
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfTcpSocket_SendPacket(sfTcpSocket* socket, sfPacket* packet);
////////////////////////////////////////////////////////////
/// Receive a packet from the host (must be connected first)
///
/// \param socket : Socket to use for receiving
/// \param packet : Packet to fill with received data
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfTcpSocket_ReceivePacket(sfTcpSocket* socket, sfPacket* packet);
#endif // SFML_TCPSOCKET_H
+43
View File
@@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// 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.
//
////////////////////////////////////////////////////////////
#ifndef SFML_NETWORK_TYPES_H
#define SFML_NETWORK_TYPES_H
typedef struct sfFtpDirectoryResponse sfFtpDirectoryResponse;
typedef struct sfFtpListingResponse sfFtpListingResponse;
typedef struct sfFtpResponse sfFtpResponse;
typedef struct sfFtp sfFtp;
typedef struct sfHttpRequest sfHttpRequest;
typedef struct sfHttpResponse sfHttpResponse;
typedef struct sfHttp sfHttp;
typedef struct sfPacket sfPacket;
typedef struct sfSocketSelector sfSocketSelector;
typedef struct sfTcpListener sfTcpListener;
typedef struct sfTcpSocket sfTcpSocket;
typedef struct sfUdpSocket sfUdpSocket;
#endif // SFML_NETWORK_TYPES_H
+162
View File
@@ -0,0 +1,162 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// 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.
//
////////////////////////////////////////////////////////////
#ifndef SFML_UDPSOCKET_H
#define SFML_UDPSOCKET_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.h>
#include <SFML/Network/IpAddress.h>
#include <SFML/Network/SocketStatus.h>
#include <SFML/Network/Types.h>
////////////////////////////////////////////////////////////
/// Construct a new UDP socket
///
/// \return Pointer to the new socket
///
////////////////////////////////////////////////////////////
CSFML_API sfUdpSocket* sfUdpSocket_Create(void);
////////////////////////////////////////////////////////////
/// Destroy an existing UDP socket
///
/// \param socket : Socket to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfUdpSocket_Destroy(sfUdpSocket* socket);
////////////////////////////////////////////////////////////
/// Change the blocking state of a UDP socket.
/// The default behaviour of a socket is blocking
///
/// \param socket : Socket to modify
/// \param blocking : Pass sfTrue to set the socket as blocking, or false for non-blocking
///
////////////////////////////////////////////////////////////
CSFML_API void sfUdpSocket_SetBlocking(sfUdpSocket* socket, sfBool blocking);
////////////////////////////////////////////////////////////
/// Get the blocking state of the socket
///
/// \param socket : Socket to read
///
/// \Return sfTrue if the socket is blocking, sfFalse otherwise
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfUdpSocket_IsBlocking(const sfUdpSocket* socket);
////////////////////////////////////////////////////////////
/// Get the port to which a socket is bound locally
///
/// \param socket : Socket to read
///
/// \return Port to which the socket is bound
///
////////////////////////////////////////////////////////////
CSFML_API unsigned short sfUdpSocket_GetLocalPort(const sfUdpSocket* socket);
////////////////////////////////////////////////////////////
/// Bind a socket to a specific port
///
/// \param socket : Socket to bind
/// \param port : Port to bind the socket to
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfUdpSocket_Bind(sfUdpSocket* socket, unsigned short port);
////////////////////////////////////////////////////////////
/// Unbind a socket from its previous port, if any
///
/// \param socket : Socket to unbind
///
////////////////////////////////////////////////////////////
CSFML_API void sfUdpSocket_Unbind(sfUdpSocket* socket);
////////////////////////////////////////////////////////////
/// Send an array of bytes
///
/// \param socket : Socket to use for sending
/// \param data : Pointer to the bytes to send
/// \param size : Number of bytes to send
/// \param address : Address of the computer to send the packet to
/// \param port : Port to use for communication
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfUdpSocket_Send(sfUdpSocket* socket, const char* data, size_t size, sfIpAddress address, unsigned short port);
////////////////////////////////////////////////////////////
/// Receive an array of bytes.
/// This function is blocking, ie. it won't return before some
/// bytes have been received
///
/// \param socket : Socket to use for receiving
/// \param data : Pointer to a byte array to fill (make sure it is big enough)
/// \param maxSize : Maximum number of bytes to read
/// \param sizeReceived : Number of bytes received
/// \param address : Address of the computer which sent the data
/// \param port : Port on which the remote computer sent the data
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfUdpSocket_Receive(sfUdpSocket* socket, char* data, size_t maxSize, size_t* sizeReceived, sfIpAddress* address, unsigned short* port);
////////////////////////////////////////////////////////////
/// Send a packet of data
///
/// \param socket : Socket to use for sending
/// \param packet : Packet to send
/// \param address : Address of the computer to send the packet to
/// \param port : Port to use for communication
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfUdpSocket_SendPacket(sfUdpSocket* socket, sfPacket* packet, sfIpAddress address, unsigned short port);
////////////////////////////////////////////////////////////
/// Receive a packet.
/// This function is blocking, ie. it won't return before a
/// packet is received
///
/// \param socket : Socket to use for receiving
/// \param packet : Packet to fill with received data
/// \param address : Address of the computer which sent the packet
/// \param port : Port on which the remote computer sent the data
///
/// \return Socket status
///
////////////////////////////////////////////////////////////
CSFML_API sfSocketStatus sfUdpSocket_ReceivePacket(sfUdpSocket* socket, sfPacket* packet, sfIpAddress* address, unsigned short* port);
#endif // SFML_UDPSOCKET_H