=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/plugin/sm1Socket.c,v retrieving revision 1.13 retrieving revision 1.16 diff -u -p -r1.13 -r1.16 --- OpenXM/src/kan96xx/plugin/sm1Socket.c 2002/10/24 02:12:35 1.13 +++ OpenXM/src/kan96xx/plugin/sm1Socket.c 2004/02/23 09:03:43 1.16 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM/src/kan96xx/plugin/sm1Socket.c,v 1.12 2002/10/24 01:29:00 takayama Exp $ */ +/* $OpenXM: OpenXM/src/kan96xx/plugin/sm1Socket.c,v 1.15 2003/09/16 02:57:40 takayama Exp $ */ /* msg0s.c */ #include #include @@ -14,6 +14,7 @@ #include "sm1Socket.h" extern int Quiet; +static int Post_debug=0; static void errorMsg1s(char *s); static int getContentLength(char *s); static int getReceivedContentLength(char *s); @@ -30,7 +31,12 @@ struct object KsocketOpen(struct object obj) { int on; int tt; extern int errno; + extern int Post_debug; + if ((char *)getenv("OXWEB_DEBUG") != NULL) { + Post_debug = 1; + } + if (obj.tag != Sarray) { errorMsg1s("KsocketOpen([optional integer,optional string name])"); } @@ -173,7 +179,11 @@ struct object KsocketAccept(struct object obj) { } s = KopInteger(obj1); if ((news = accept(s,NULL,NULL)) < 0) { - errorMsg1s("Error in accept."); + fprintf(stderr,"Error in accept. Retrying (KsocketAccept).\n"); + /* Code added for strange behavior on cygwin. */ + if ((news = accept(s,NULL,NULL)) < 0) { + errorMsg1s("Error in accept. Retry failed."); + } } if (close(s) < 0) { errorMsg1s("Error in closing the old socket."); @@ -209,7 +219,11 @@ struct object KsocketAccept2(struct object obj) { } s = KopInteger(obj1); if ((news = accept(s,NULL,NULL)) < 0) { - errorMsg1s("Error in accept."); + fprintf(stderr,"Error in accept. Retrying (KsocketAccept2).\n"); + /* Code added for strange behavior on cygwin. */ + if ((news = accept(s,NULL,NULL)) < 0) { + errorMsg1s("Error in accept. Retry failed."); + } } if (close(s) < 0) { errorMsg1s("Error in closing the old socket."); @@ -399,8 +413,8 @@ struct object KsocketRead(struct object obj) { errorMsg1s("Select returns 1, but there is no data to read."); } }else { /* increase the datasize */ - tmp = (char *)GC_malloc(sizeof(char)*2*datasize); - /*I should use GC_malloc_atomic and free after finishing this function?*/ + tmp = (char *)sGC_malloc(sizeof(char)*2*datasize); + /*I should use sGC_malloc_atomic and free after finishing this function?*/ if (tmp == (char *)NULL) errorMsg1s("Out of Memory."); bcopy(data,tmp,totalsize); data = tmp; @@ -408,7 +422,7 @@ struct object KsocketRead(struct object obj) { } } - r = (char *)GC_malloc(sizeof(char)*(totalsize+1)); + r = (char *)sGC_malloc(sizeof(char)*(totalsize+1)); if (r == (char *)NULL) errorMsg1s("Out of Memory."); bcopy(data,r,totalsize); r[totalsize] = 0; @@ -582,6 +596,7 @@ struct object KsocketReadHTTP(struct object socketObj) int last; int contentLength=-1; int socketid; + extern int Post_debug; nob = NullObject; if (socketObj.tag != Sarray) { @@ -630,22 +645,26 @@ struct object KsocketReadHTTP(struct object socketObj) break; } } - fprintf(stderr,"Waiting in socketReadBlock. flagmax(0d,0a)=%d, content-length=%d, received content-length=%d\n",flagmax,contentLength,getReceivedContentLength(sss)); + if (Post_debug) { + fprintf(stderr,"Waiting in socketReadBlock. flagmax(0d,0a)=%d, content-length=%d, received content-length=%d\n",flagmax,contentLength,getReceivedContentLength(sss)); + } if (strlen(s) == 0) { fprintf(stderr,"No data. Perhaps connection is closed by foreign host.\n"); return nob; }else{ /* for debugging. */ - for (i=0; i= ' ') && (sss[i] < 0x7f)) { - fprintf(stderr,"%c",sss[i]); - }else{ - fprintf(stderr,"(%3x)",sss[i]); - if (sss[i] == 0xa) fprintf(stderr,"\n"); - } + if (Post_debug) { + for (i=0; i= ' ') && (sss[i] < 0x7f)) { + fprintf(stderr,"%c",sss[i]); + }else{ + fprintf(stderr,"(%3x)",sss[i]); + if (sss[i] == 0xa) fprintf(stderr,"\n"); + } + } + fprintf(stderr,"\n"); } - fprintf(stderr,"\n"); } if (KsocketSelect0(socketid,-1) != 1) { @@ -665,7 +684,7 @@ struct object KsocketReadHTTP(struct object socketObj) } } if (datasize-1 <= strlen(sss)+strlen(s)) { - tmp = (char *)GC_malloc(sizeof(char)*2*(datasize+strlen(s))+1); + tmp = (char *)sGC_malloc(sizeof(char)*2*(datasize+strlen(s))+1); if (tmp == (char *)NULL) errorMsg1s("Out of Memory."); strcpy(tmp,sss); strcat(tmp,s); @@ -769,7 +788,7 @@ struct object KsocketGetHostName(void) { if (gethostname(name,1023) != 0) { return rob; } - s = (char *)GC_malloc(sizeof(char)*(strlen(name)+2)); + s = (char *)sGC_malloc(sizeof(char)*(strlen(name)+2)); if (s == (char *)NULL) errorMsg1s("Out of Memory."); strcpy(s,name); return(KpoString(s));