projects
/
umurmur.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
3897549
)
Use a function to find a free Session ID instead of just incrementing a counter.
author
fatbob313
<martin@fatbob.nu>
Sun, 31 Jan 2010 13:13:13 +0000
(13:13 +0000)
committer
fatbob313
<martin@fatbob.nu>
Sun, 31 Jan 2010 13:13:13 +0000
(13:13 +0000)
src/client.c
patch
|
blob
|
history
diff --git
a/src/client.c
b/src/client.c
index 1ef55f0b7bab590be65b92fde71c43d31609bc11..95b30aa3f4e9f562a518e81abbe7678fcbd8ca0a 100644
(file)
--- a/
src/client.c
+++ b/
src/client.c
@@
-51,7
+51,6
@@
void Client_free(client_t *client);
declare_list(clients);
static int clientcount; /* = 0 */
declare_list(clients);
static int clientcount; /* = 0 */
-static int session = 1;
static int maxBandwidth;
int iCodecAlpha, iCodecBeta;
static int maxBandwidth;
int iCodecAlpha, iCodecBeta;
@@
-162,6
+161,23
@@
void recheckCodecVersions()
}
}
+static int findFreeSessionId()
+{
+ int id;
+ client_t *itr = NULL;
+
+ for (id = 1; id < INT_MAX; id++) {
+ itr = NULL;
+ while ((itr = Client_iterate(&itr)) != NULL) {
+ if (itr->sessionId == id)
+ break;
+ }
+ if (itr == NULL) /* Found free id */
+ return id;
+ }
+ return -1;
+}
+
int Client_add(int fd, struct sockaddr_in *remote)
{
client_t *newclient;
int Client_add(int fd, struct sockaddr_in *remote)
{
client_t *newclient;
@@
-183,7
+199,9
@@
int Client_add(int fd, struct sockaddr_in *remote)
}
newclient->availableBandwidth = maxBandwidth;
Timer_init(&newclient->lastActivity);
}
newclient->availableBandwidth = maxBandwidth;
Timer_init(&newclient->lastActivity);
- newclient->sessionId = session++; /* XXX - more elaborate? */
+ newclient->sessionId = findFreeSessionId();
+ if (newclient->sessionId < 0)
+ Log_fatal("Could not find a free session ID");
init_list_entry(&newclient->txMsgQueue);
init_list_entry(&newclient->chan_node);
init_list_entry(&newclient->txMsgQueue);
init_list_entry(&newclient->chan_node);