Procházet zdrojové kódy

rest of the host functions, docs

leaf corcoran před 14 roky
rodič
revize
14fb5f9920
2 změnil soubory, kde provedl 32 přidání a 7 odebrání
  1. 11 3
      docs/docs.md
  2. 21 4
      enet.c

+ 11 - 3
docs/docs.md

@@ -112,7 +112,6 @@ Parameters:
 
 ### `host:connect(address [, channels_count, data])`
 Connects a host to a remote host. Returns peer object associated with remote host.
-
 The actual connection will not take place until the next `host:service` done,
 in which a `"connect"` event will be generated.
 
@@ -125,7 +124,6 @@ Defaults to `0`.
 ### `host:service([timeout])`
 Wait for events, send and receive any ready packets. `timeout` is the max
 number of milliseconds to be wait for an event. By default `timeout` is `0`.
-
 Returns `nil` on timeout if not events occurred.
 
 If an event happens an event table is returned. All events have a `type` entry,
@@ -143,6 +141,13 @@ associated event if something was dispatched, otherwise `nil`.
 Sends any queued packets. This is only required to send packets earlier than
 the next call to `host:service`, or if `host:service` will not be called again.
 
+### `host:channel_limit(limit)`
+Sets the maximum number of channels allowed. If it is `0` then the system
+maximum allowable value is used.
+
+### `host:bandwidth_limit(incoming, outgoing)`
+Sets the bandwidth limits of the host in bytes/sec. Set to `0` for unlimited.
+
 ### `peer:send(data [, channel, flag])`
 Queues  a packet to be sent to dir. `data` is the contents of the packet, it
 must be a Lua string.
@@ -192,10 +197,13 @@ Parameters:
 
 ### `peer:receive()`
 Attempts to dequeue an incoming packet for this peer.
-
 Returns `nil` if there are no packets waiting. Otherwise returns two values:
 the string representing the packet data, and the channel the packet came from.
 
 <a name="contact"></a>
 ## Contact
 
+Author: Leaf Corcoran (leafo)  
+Email: <[email protected]>  
+Homepage: <http://leafo.net>  
+

+ 21 - 4
enet.c

@@ -145,7 +145,7 @@ static ENetPacket *read_packet(lua_State *l, int idx, enet_uint8 *channel_id) {
 			luaL_error(l, "Unknown packet flag: %s", flag_str);
 		}
 	}
-	if (argc >= idx+1 && lua_isnil(l, idx+1)) {
+	if (argc >= idx+1 && !lua_isnil(l, idx+1)) {
 		*channel_id = luaL_checkint(l, idx+1);
 	}
 
@@ -157,8 +157,6 @@ static ENetPacket *read_packet(lua_State *l, int idx, enet_uint8 *channel_id) {
 	return packet;
 }
 
-
-
 /**
  * Create a new host
  * Args:
@@ -287,11 +285,26 @@ static int host_broadcast(lua_State *l) {
 
 	enet_uint8 channel_id;
 	ENetPacket *packet = read_packet(l, 2, &channel_id);
-
 	enet_host_broadcast(host, channel_id, packet);
 	return 0;
 }
 
+// Args: limit:number
+static int host_channel_limit(lua_State *l) {
+	ENetHost *host = check_host(l, 1);
+	int limit = luaL_checkint(l, 2);
+	enet_host_channel_limit(host, limit);
+	return 0;
+}
+
+static int host_bandwidth_limit(lua_State *l) {
+	ENetHost *host = check_host(l, 1);
+	enet_uint32 in_bandwidth = luaL_checkint(l, 2);
+	enet_uint32 out_bandwidth = luaL_checkint(l, 2);
+	enet_host_bandwidth_limit(host, in_bandwidth, out_bandwidth);
+	return 0;
+}
+
 static int host_gc(lua_State *l) {
 	ENetHost *host = check_host(l, 1);
 	enet_host_destroy(host);
@@ -390,6 +403,7 @@ static int peer_send(lua_State *l) {
 	enet_uint8 channel_id;
 	ENetPacket *packet = read_packet(l, 2, &channel_id);
 
+	printf("sending, channel_id=%d\n", channel_id);
 	enet_peer_send(peer, channel_id, packet);
 	return 0;
 }
@@ -405,6 +419,8 @@ static const struct luaL_Reg enet_host_funcs [] = {
 	{"connect", host_connect},
 	{"broadcast", host_broadcast},
 	{"flush", host_flush},
+	{"channel_limit", host_channel_limit},
+	{"bandwidth_limit", host_bandwidth_limit},
 	{NULL, NULL}
 };
 
@@ -416,6 +432,7 @@ static const struct luaL_Reg enet_peer_funcs [] = {
 	{"ping", peer_ping},
 	{"receive", peer_receive},
 	{"send", peer_send},
+	{"throttle_configure", peer_throttle_configure},
 	{NULL, NULL}
 };