miniupnpc: Improvements in testminiwget.sh
This commit is contained in:
parent
aefb519168
commit
f63cbf0935
|
@ -1,6 +1,9 @@
|
|||
$Id: Changelog.txt,v 1.169 2012/05/24 18:08:49 nanard Exp $
|
||||
$Id: Changelog.txt,v 1.171 2012/06/20 21:05:56 nanard Exp $
|
||||
miniUPnP client Changelog.
|
||||
|
||||
2012/05/29
|
||||
Improvements in testminiwget.sh
|
||||
|
||||
VERSION 1.7 : released 2012/05/24
|
||||
|
||||
2012/05/01:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $Id: minihttptestserver.c,v 1.11 2012/05/21 08:47:38 nanard Exp $ */
|
||||
/* $Id: minihttptestserver.c,v 1.13 2012/05/29 13:03:07 nanard Exp $ */
|
||||
/* Project : miniUPnP
|
||||
* Author : Thomas Bernard
|
||||
* Copyright (c) 2011 Thomas Bernard
|
||||
* Copyright (c) 2011-2012 Thomas Bernard
|
||||
* This software is subject to the conditions detailed in the
|
||||
* LICENCE file provided in this distribution.
|
||||
* */
|
||||
|
@ -16,6 +16,7 @@
|
|||
#include <netinet/in.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define CRAP_LENGTH (2048)
|
||||
|
||||
|
@ -129,8 +130,10 @@ char * build_chunked_response(int content_length, int * response_len) {
|
|||
response_buffer[(*response_len)++] = '\r';
|
||||
response_buffer[(*response_len)++] = '\n';
|
||||
}
|
||||
memcpy(response_buffer + *response_len, "0\r\n", 3);
|
||||
*response_len += 3;
|
||||
/* the last chunk : "0\r\n" a empty body and then
|
||||
* the final "\r\n" */
|
||||
memcpy(response_buffer + *response_len, "0\r\n\r\n", 5);
|
||||
*response_len += 5;
|
||||
free(content_buffer);
|
||||
|
||||
printf("resp_length=%d buffer_length=%d content_length=%d\n",
|
||||
|
@ -161,8 +164,11 @@ void send_response(int c, const char * buffer, int len)
|
|||
n = len;
|
||||
n = write(c, buffer, n);
|
||||
if(n < 0) {
|
||||
perror("write");
|
||||
return;
|
||||
if(errno != EINTR) {
|
||||
perror("write");
|
||||
return;
|
||||
}
|
||||
/* if errno == EINTR, try again */
|
||||
} else {
|
||||
len -= n;
|
||||
buffer += n;
|
||||
|
@ -258,11 +264,14 @@ void handle_http_connection(int c)
|
|||
while(n > 0) {
|
||||
i = write(c, pc, n);
|
||||
if(i<0) {
|
||||
perror("write");
|
||||
return;
|
||||
if(errno != EINTR) {
|
||||
perror("write");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
n -= i;
|
||||
pc += i;
|
||||
}
|
||||
n -= i;
|
||||
pc += i;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/sh
|
||||
# $Id: testminiwget.sh,v 1.4 2011/05/09 08:53:15 nanard Exp $
|
||||
# $Id: testminiwget.sh,v 1.6 2012/05/29 13:03:40 nanard Exp $
|
||||
# project miniupnp : http://miniupnp.free.fr/
|
||||
# (c) 2011 Thomas Bernard
|
||||
# (c) 2011-2012 Thomas Bernard
|
||||
#
|
||||
# test program for miniwget.c
|
||||
# is usually invoked by "make check"
|
||||
|
@ -12,10 +12,13 @@
|
|||
# 3 - compares served and received data
|
||||
# 4 - kills the local HTTP server and exits
|
||||
#
|
||||
# The script was tested and works with ksh, bash
|
||||
# It fails to run with dash 0.5.5.1 because of "kill %1"
|
||||
|
||||
HTTPSERVEROUT=/tmp/httpserverout
|
||||
EXPECTEDFILE=/tmp/expectedfile
|
||||
DOWNLOADEDFILE=/tmp/downloadedfile
|
||||
TMPDIR=`mktemp -d`
|
||||
HTTPSERVEROUT="${TMPDIR}/httpserverout"
|
||||
EXPECTEDFILE="${TMPDIR}/expectedfile"
|
||||
DOWNLOADEDFILE="${TMPDIR}/downloadedfile"
|
||||
#ADDR=localhost
|
||||
ADDR="[::1]"
|
||||
PORT=
|
||||
|
@ -26,7 +29,8 @@ RET=0
|
|||
|
||||
# launching the test HTTP server
|
||||
./minihttptestserver -6 -e $EXPECTEDFILE > $HTTPSERVEROUT &
|
||||
while [ "$PORT" == "" ]; do
|
||||
while [ -z "$PORT" ]; do
|
||||
sleep 1
|
||||
PORT=`cat $HTTPSERVEROUT | sed 's/Listening on port \([0-9]*\)/\1/' `
|
||||
done
|
||||
echo "Test HTTP server is listening on $PORT"
|
||||
|
@ -72,8 +76,10 @@ if [ $RET -eq 0 ]; then
|
|||
rm -f "${DOWNLOADEDFILE}.2"
|
||||
rm -f "${DOWNLOADEDFILE}.3"
|
||||
rm -f $EXPECTEDFILE $HTTPSERVEROUT
|
||||
rmdir ${TMPDIR}
|
||||
else
|
||||
echo "at least one of the test FAILED"
|
||||
echo "directory ${TMPDIR} is left intact"
|
||||
fi
|
||||
exit $RET
|
||||
|
||||
|
|
Loading…
Reference in New Issue