(svn r7836) -Codechange: some constness for network/core.

This commit is contained in:
rubidium 2007-01-04 21:48:52 +00:00
parent b2f85eb044
commit 73079f83bc
8 changed files with 18 additions and 18 deletions

View File

@ -68,7 +68,7 @@ bool NetworkCoreInitialize(void)
void NetworkCoreShutdown(void) void NetworkCoreShutdown(void)
{ {
#if defined(__MORPHOS__) || defined(__AMIGA__) #if defined(__MORPHOS__) || defined(__AMIGA__)
/* free allocated ressources */ /* free allocated resources */
#if defined(__AMIGA__) #if defined(__AMIGA__)
if (TimerBase != NULL) CloseDevice((struct IORequest*)TimerRequest); // XXX This smells wrong if (TimerBase != NULL) CloseDevice((struct IORequest*)TimerRequest); // XXX This smells wrong
if (TimerRequest != NULL) DeleteIORequest(TimerRequest); if (TimerRequest != NULL) DeleteIORequest(TimerRequest);

View File

@ -150,7 +150,7 @@ typedef unsigned long in_addr_t;
# endif # endif
#endif // __MORPHOS__ || __AMIGA__ #endif // __MORPHOS__ || __AMIGA__
static inline bool SetNonBlocking(int d) static inline bool SetNonBlocking(const int d)
{ {
#ifdef WIN32 #ifdef WIN32
u_long nonblocking = 1; u_long nonblocking = 1;
@ -164,7 +164,7 @@ static inline bool SetNonBlocking(int d)
#endif #endif
} }
static inline bool SetNoDelay(int d) static inline bool SetNoDelay(const int d)
{ {
/* XXX should this be done at all? */ /* XXX should this be done at all? */
#if !defined(BEOS_NET_SERVER) // not implemented on BeOS net_server #if !defined(BEOS_NET_SERVER) // not implemented on BeOS net_server

View File

@ -22,7 +22,7 @@ extern void NORETURN CDECL error(const char *str, ...);
* @param type the of packet * @param type the of packet
* @return the newly created packet * @return the newly created packet
*/ */
Packet *NetworkSend_Init(PacketType type) Packet *NetworkSend_Init(const PacketType type)
{ {
Packet *packet = malloc(sizeof(Packet)); Packet *packet = malloc(sizeof(Packet));
/* An error is inplace here, because it simply means we ran out of memory. */ /* 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); extern uint CloseConnection(NetworkClientState *cs);
/** Is it safe to read from the packet, i.e. didn't we run over the buffer ? */ /** 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 */ /* Don't allow reading from a closed socket */
if (HasClientQuit(cs)) return false; if (HasClientQuit(cs)) return false;

View File

@ -21,7 +21,7 @@ typedef struct NetworkClientState NetworkClientState;
* @param cs the state to query * @param cs the state to query
* @param true if the connection should be considered dropped * @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 uint16 PacketSize; ///< Size of the whole packet.
typedef uint8 PacketType; ///< Identifier for the packet typedef uint8 PacketType; ///< Identifier for the packet
@ -49,7 +49,7 @@ typedef struct Packet {
} Packet; } Packet;
Packet *NetworkSend_Init(PacketType type); Packet *NetworkSend_Init(const PacketType type);
void NetworkSend_FillPacketSize(Packet *packet); void NetworkSend_FillPacketSize(Packet *packet);
void NetworkSend_uint8 (Packet *packet, uint8 data); void NetworkSend_uint8 (Packet *packet, uint8 data);
void NetworkSend_uint16(Packet *packet, uint16 data); void NetworkSend_uint16(Packet *packet, uint16 data);

View File

@ -46,7 +46,7 @@ NetworkRecvStatus CloseConnection(NetworkClientState *cs)
* @param cs the client to check * @param cs the client to check
* @return true if the client has quit * @return true if the client has quit
*/ */
bool HasClientQuit(NetworkClientState *cs) bool HasClientQuit(const NetworkClientState *cs)
{ {
return cs->has_quit; return cs->has_quit;
} }

View File

@ -20,7 +20,7 @@
* @param broadcast whether to allow broadcast sending/receiving * @param broadcast whether to allow broadcast sending/receiving
* @return true if the listening succeeded * @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; struct sockaddr_in sin;
@ -85,7 +85,7 @@ void NetworkUDPClose(SOCKET *udp)
* @param p the packet to send * @param p the packet to send
* @param recv the receiver (target) of the packet * @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; int res;
@ -102,7 +102,7 @@ void NetworkSendUDP_Packet(SOCKET udp, Packet *p, struct sockaddr_in *recv)
* Receive a packet at UDP level * Receive a packet at UDP level
* @param udp the socket to receive the packet on * @param udp the socket to receive the packet on
*/ */
void NetworkUDPReceive(SOCKET udp) void NetworkUDPReceive(const SOCKET udp)
{ {
struct sockaddr_in client_addr; struct sockaddr_in client_addr;
socklen_t client_len; socklen_t client_len;

View File

@ -16,11 +16,11 @@
///** Sending/receiving of UDP packets **//// ///** 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 NetworkUDPClose(SOCKET *udp);
void NetworkSendUDP_Packet(SOCKET udp, Packet *p, struct sockaddr_in *recv); void NetworkSendUDP_Packet(const SOCKET udp, Packet *p, const struct sockaddr_in *recv);
void NetworkUDPReceive(SOCKET udp); void NetworkUDPReceive(const SOCKET udp);
/** /**
* Function that is called for every received UDP packet. * Function that is called for every received UDP packet.
@ -28,7 +28,7 @@ void NetworkUDPReceive(SOCKET udp);
* @param packet the received packet * @param packet the received packet
* @param client_addr the address of the sender of the 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 **//// ///** Sending/receiving of (large) chuncks of UDP packets **////

View File

@ -28,7 +28,7 @@ enum {
ADVERTISE_RETRY_TIMES = 3 // give up readvertising after this much failed retries 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; static NetworkClientState _udp_cs;
@ -403,7 +403,7 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVER_NEWGRFS)
* game information of some 'random' host. * game information of some 'random' host.
*/ */
typedef struct NetworkUDPPacketAndSocket { 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; SOCKET *incoming_socket;
} NetworkUPDPacketAndSocket; } NetworkUPDPacketAndSocket;
@ -421,7 +421,7 @@ static const NetworkUPDPacketAndSocket _network_udp_packet[PACKET_UDP_END] = {
{ RECEIVE_COMMAND(PACKET_UDP_SERVER_NEWGRFS), &_udp_client_socket }, { 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; byte type;