mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r7836) -Codechange: some constness for network/core.
This commit is contained in:
parent
b2f85eb044
commit
73079f83bc
|
@ -68,7 +68,7 @@ bool NetworkCoreInitialize(void)
|
|||
void NetworkCoreShutdown(void)
|
||||
{
|
||||
#if defined(__MORPHOS__) || defined(__AMIGA__)
|
||||
/* free allocated ressources */
|
||||
/* free allocated resources */
|
||||
#if defined(__AMIGA__)
|
||||
if (TimerBase != NULL) CloseDevice((struct IORequest*)TimerRequest); // XXX This smells wrong
|
||||
if (TimerRequest != NULL) DeleteIORequest(TimerRequest);
|
||||
|
|
|
@ -150,7 +150,7 @@ typedef unsigned long in_addr_t;
|
|||
# endif
|
||||
#endif // __MORPHOS__ || __AMIGA__
|
||||
|
||||
static inline bool SetNonBlocking(int d)
|
||||
static inline bool SetNonBlocking(const int d)
|
||||
{
|
||||
#ifdef WIN32
|
||||
u_long nonblocking = 1;
|
||||
|
@ -164,7 +164,7 @@ static inline bool SetNonBlocking(int d)
|
|||
#endif
|
||||
}
|
||||
|
||||
static inline bool SetNoDelay(int d)
|
||||
static inline bool SetNoDelay(const int d)
|
||||
{
|
||||
/* XXX should this be done at all? */
|
||||
#if !defined(BEOS_NET_SERVER) // not implemented on BeOS net_server
|
||||
|
|
|
@ -22,7 +22,7 @@ extern void NORETURN CDECL error(const char *str, ...);
|
|||
* @param type the of packet
|
||||
* @return the newly created packet
|
||||
*/
|
||||
Packet *NetworkSend_Init(PacketType type)
|
||||
Packet *NetworkSend_Init(const PacketType type)
|
||||
{
|
||||
Packet *packet = malloc(sizeof(Packet));
|
||||
/* An error is inplace here, because it simply means we ran out of memory. */
|
||||
|
@ -112,7 +112,7 @@ void NetworkSend_string(Packet *packet, const char* data)
|
|||
extern uint CloseConnection(NetworkClientState *cs);
|
||||
|
||||
/** Is it safe to read from the packet, i.e. didn't we run over the buffer ? */
|
||||
static inline bool CanReadFromPacket(NetworkClientState *cs, Packet *packet, uint bytes_to_read)
|
||||
static inline bool CanReadFromPacket(NetworkClientState *cs, const Packet *packet, const uint bytes_to_read)
|
||||
{
|
||||
/* Don't allow reading from a closed socket */
|
||||
if (HasClientQuit(cs)) return false;
|
||||
|
|
|
@ -21,7 +21,7 @@ typedef struct NetworkClientState NetworkClientState;
|
|||
* @param cs the state to query
|
||||
* @param true if the connection should be considered dropped
|
||||
*/
|
||||
bool HasClientQuit(NetworkClientState *cs);
|
||||
bool HasClientQuit(const NetworkClientState *cs);
|
||||
|
||||
typedef uint16 PacketSize; ///< Size of the whole packet.
|
||||
typedef uint8 PacketType; ///< Identifier for the packet
|
||||
|
@ -49,7 +49,7 @@ typedef struct Packet {
|
|||
} Packet;
|
||||
|
||||
|
||||
Packet *NetworkSend_Init(PacketType type);
|
||||
Packet *NetworkSend_Init(const PacketType type);
|
||||
void NetworkSend_FillPacketSize(Packet *packet);
|
||||
void NetworkSend_uint8 (Packet *packet, uint8 data);
|
||||
void NetworkSend_uint16(Packet *packet, uint16 data);
|
||||
|
|
|
@ -46,7 +46,7 @@ NetworkRecvStatus CloseConnection(NetworkClientState *cs)
|
|||
* @param cs the client to check
|
||||
* @return true if the client has quit
|
||||
*/
|
||||
bool HasClientQuit(NetworkClientState *cs)
|
||||
bool HasClientQuit(const NetworkClientState *cs)
|
||||
{
|
||||
return cs->has_quit;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
* @param broadcast whether to allow broadcast sending/receiving
|
||||
* @return true if the listening succeeded
|
||||
*/
|
||||
bool NetworkUDPListen(SOCKET *udp, uint32 host, uint16 port, bool broadcast)
|
||||
bool NetworkUDPListen(SOCKET *udp, const uint32 host, const uint16 port, const bool broadcast)
|
||||
{
|
||||
struct sockaddr_in sin;
|
||||
|
||||
|
@ -85,7 +85,7 @@ void NetworkUDPClose(SOCKET *udp)
|
|||
* @param p the packet to send
|
||||
* @param recv the receiver (target) of the packet
|
||||
*/
|
||||
void NetworkSendUDP_Packet(SOCKET udp, Packet *p, struct sockaddr_in *recv)
|
||||
void NetworkSendUDP_Packet(const SOCKET udp, Packet *p, const struct sockaddr_in *recv)
|
||||
{
|
||||
int res;
|
||||
|
||||
|
@ -102,7 +102,7 @@ void NetworkSendUDP_Packet(SOCKET udp, Packet *p, struct sockaddr_in *recv)
|
|||
* Receive a packet at UDP level
|
||||
* @param udp the socket to receive the packet on
|
||||
*/
|
||||
void NetworkUDPReceive(SOCKET udp)
|
||||
void NetworkUDPReceive(const SOCKET udp)
|
||||
{
|
||||
struct sockaddr_in client_addr;
|
||||
socklen_t client_len;
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
|
||||
///** Sending/receiving of UDP packets **////
|
||||
|
||||
bool NetworkUDPListen(SOCKET *udp, uint32 host, uint16 port, bool broadcast);
|
||||
bool NetworkUDPListen(SOCKET *udp, const uint32 host, const uint16 port, const bool broadcast);
|
||||
void NetworkUDPClose(SOCKET *udp);
|
||||
|
||||
void NetworkSendUDP_Packet(SOCKET udp, Packet *p, struct sockaddr_in *recv);
|
||||
void NetworkUDPReceive(SOCKET udp);
|
||||
void NetworkSendUDP_Packet(const SOCKET udp, Packet *p, const struct sockaddr_in *recv);
|
||||
void NetworkUDPReceive(const SOCKET udp);
|
||||
|
||||
/**
|
||||
* Function that is called for every received UDP packet.
|
||||
|
@ -28,7 +28,7 @@ void NetworkUDPReceive(SOCKET udp);
|
|||
* @param packet the received packet
|
||||
* @param client_addr the address of the sender of the packet
|
||||
*/
|
||||
void NetworkHandleUDPPacket(SOCKET udp, Packet *p, struct sockaddr_in *client_addr);
|
||||
void NetworkHandleUDPPacket(const SOCKET udp, Packet *p, const struct sockaddr_in *client_addr);
|
||||
|
||||
|
||||
///** Sending/receiving of (large) chuncks of UDP packets **////
|
||||
|
|
|
@ -28,7 +28,7 @@ enum {
|
|||
ADVERTISE_RETRY_TIMES = 3 // give up readvertising after this much failed retries
|
||||
};
|
||||
|
||||
#define DEF_UDP_RECEIVE_COMMAND(type) void NetworkPacketReceive_ ## type ## _command(Packet *p, struct sockaddr_in *client_addr)
|
||||
#define DEF_UDP_RECEIVE_COMMAND(type) void NetworkPacketReceive_ ## type ## _command(Packet *p, const struct sockaddr_in *client_addr)
|
||||
|
||||
static NetworkClientState _udp_cs;
|
||||
|
||||
|
@ -403,7 +403,7 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVER_NEWGRFS)
|
|||
* game information of some 'random' host.
|
||||
*/
|
||||
typedef struct NetworkUDPPacketAndSocket {
|
||||
void (*callback)(Packet *p, struct sockaddr_in *client_addr);
|
||||
void (*callback)(Packet *p, const struct sockaddr_in *client_addr);
|
||||
SOCKET *incoming_socket;
|
||||
} NetworkUPDPacketAndSocket;
|
||||
|
||||
|
@ -421,7 +421,7 @@ static const NetworkUPDPacketAndSocket _network_udp_packet[PACKET_UDP_END] = {
|
|||
{ RECEIVE_COMMAND(PACKET_UDP_SERVER_NEWGRFS), &_udp_client_socket },
|
||||
};
|
||||
|
||||
void NetworkHandleUDPPacket(SOCKET udp, Packet *p, struct sockaddr_in *client_addr)
|
||||
void NetworkHandleUDPPacket(const SOCKET udp, Packet *p, const struct sockaddr_in *client_addr)
|
||||
{
|
||||
byte type;
|
||||
|
||||
|
|
Loading…
Reference in New Issue