Fixed tcptest to not do send recv or close on a socket that's not connected.

This keeps the user from doing something inappropriate.
makefile: add -g back in

svn path=/trunk/; revision=10952
This commit is contained in:
Art Yerkes 2004-09-21 04:06:15 +00:00
parent 6f6e411eef
commit fa965094ed
2 changed files with 15 additions and 4 deletions

View file

@ -1,5 +1,5 @@
#
# $Id: makefile,v 1.4 2004/09/13 03:14:35 royce Exp $
# $Id: makefile,v 1.5 2004/09/21 04:06:15 arty Exp $
PATH_TO_TOP = ../../..
@ -19,6 +19,8 @@ TARGET_CPPFLAGS = -I$(PATH_TO_TOP)/drivers/lib/oskittcp/include -I$(PATH_TO_TOP
TARGET_GCCLIBS = stdc++
TARGET_LDFLAGS = -g
include $(PATH_TO_TOP)/rules.mak
include $(TOOLS_PATH)/helper.mk

View file

@ -178,10 +178,10 @@ void display_row( char *data, int off, int len ) {
int main( int argc, char **argv ) {
int asock = INVALID_SOCKET, selret, dgrecv, fromsize, err, port = 5001;
char datagram[MAX_DG_SIZE];
void *conn;
void *conn = 0;
struct fd_set readf;
struct timeval tv;
struct sockaddr_in addr_from = { AF_INET }, addr_to;
struct sockaddr_in addr_from = { AF_INET }, addr_to = { AF_INET };
std::list<std::string>::iterator i;
WSADATA wsadata;
@ -201,6 +201,9 @@ int main( int argc, char **argv ) {
return 0;
}
addr_to.sin_port = htons( port & (~1) );
addr_to.sin_addr.s_addr = inet_addr("127.0.0.1");
while( true ) {
FD_ZERO( &readf );
FD_SET( asock, &readf );
@ -241,7 +244,12 @@ int main( int argc, char **argv ) {
} else {
printf( "Socket created\n" );
}
} else if( word == "recv" ) {
}
/* The rest of the commands apply only to an open socket */
if( !conn ) continue;
if( word == "recv" ) {
cmdin >> bytes;
if( (err = OskitTCPRecv( conn, (OSK_PCHAR)datagram,
@ -302,6 +310,7 @@ int main( int argc, char **argv ) {
}
} else if( word == "close" ) {
OskitTCPClose( conn );
conn = NULL;
}
} else if( dgrecv > 14 ) {
addr_to = addr_from;