Don't accept connections if the connection queue is full.
This commit is contained in:
parent
1d9ed5dcbf
commit
90a74c3b0a
2 changed files with 29 additions and 30 deletions
|
@ -276,30 +276,6 @@ HttpSendHeaders(HttpServerContext * c)
|
||||||
fprintf(fp, "\n");
|
fprintf(fp, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
QueueConnection(HttpServer * server, int fd)
|
|
||||||
{
|
|
||||||
FILE *fp;
|
|
||||||
int result;
|
|
||||||
|
|
||||||
if (!server)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
fp = fdopen(fd, "r+");
|
|
||||||
if (!fp)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_lock(&server->connQueueMutex);
|
|
||||||
result = QueuePush(server->connQueue, fp);
|
|
||||||
pthread_mutex_unlock(&server->connQueueMutex);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FILE *
|
static FILE *
|
||||||
DequeueConnection(HttpServer * server)
|
DequeueConnection(HttpServer * server)
|
||||||
{
|
{
|
||||||
|
@ -699,6 +675,7 @@ HttpServerEventThread(void *args)
|
||||||
int connFd;
|
int connFd;
|
||||||
int pollResult;
|
int pollResult;
|
||||||
|
|
||||||
|
|
||||||
pollResult = poll(pollFds, 1, 500);
|
pollResult = poll(pollFds, 1, 500);
|
||||||
|
|
||||||
if (pollResult < 0)
|
if (pollResult < 0)
|
||||||
|
@ -707,14 +684,32 @@ HttpServerEventThread(void *args)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_lock(&server->connQueueMutex);
|
||||||
|
|
||||||
|
/* Don't even accept connections if the queue is full. */
|
||||||
|
if (!QueueFull(server->connQueue))
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
connFd = accept(server->sd, (struct sockaddr *) & addr, &addrLen);
|
connFd = accept(server->sd, (struct sockaddr *) & addr, &addrLen);
|
||||||
|
|
||||||
if (connFd < 0)
|
if (connFd < 0)
|
||||||
{
|
{
|
||||||
|
pthread_mutex_unlock(&server->connQueueMutex);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueConnection(server, connFd);
|
fp = fdopen(connFd, "r+");
|
||||||
|
if (!fp)
|
||||||
|
{
|
||||||
|
pthread_mutex_unlock(&server->connQueueMutex);
|
||||||
|
close(connFd);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QueuePush(server->connQueue, fp);
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&server->connQueueMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < server->nThreads; i++)
|
for (i = 0; i < server->nThreads; i++)
|
||||||
|
|
|
@ -108,7 +108,11 @@ recipe_build() {
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $do_rebuild -eq 1 ] || [ ! -f "../build/$PROG" ]; then
|
if [ $do_rebuild -eq 1 ] || [ ! -f "../build/$PROG" ]; then
|
||||||
|
if [ -t 1 ]; then
|
||||||
|
printf "LD %s%*c\n" "$PROG" "16" " "
|
||||||
|
else
|
||||||
echo "LD $PROG"
|
echo "LD $PROG"
|
||||||
|
fi
|
||||||
$CC $LDFLAGS -o "../build/$PROG" $objs
|
$CC $LDFLAGS -o "../build/$PROG" $objs
|
||||||
else
|
else
|
||||||
echo "Up to date."
|
echo "Up to date."
|
||||||
|
|
Loading…
Reference in a new issue