version 1.13, 2002/10/24 02:12:35 |
version 1.20, 2005/07/03 11:08:54 |
|
|
/* $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.19 2005/06/16 05:07:24 takayama Exp $ */ |
/* msg0s.c */ |
/* msg0s.c */ |
#include <stdio.h> |
#include <stdio.h> |
|
#include <string.h> |
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <sys/socket.h> |
#include <sys/time.h> |
#include <sys/time.h> |
#include <netinet/in.h> |
#include <netinet/in.h> |
#include <netdb.h> |
#include <netdb.h> |
|
#include <errno.h> |
|
|
|
|
#include "datatype.h" |
#include "datatype.h" |
|
|
#include "sm1Socket.h" |
#include "sm1Socket.h" |
|
|
extern int Quiet; |
extern int Quiet; |
|
static int Post_debug=0; |
static void errorMsg1s(char *s); |
static void errorMsg1s(char *s); |
static int getContentLength(char *s); |
static int getContentLength(char *s); |
static int getReceivedContentLength(char *s); |
static int getReceivedContentLength(char *s); |
Line 29 struct object KsocketOpen(struct object obj) { |
|
Line 32 struct object KsocketOpen(struct object obj) { |
|
int s_waiting; |
int s_waiting; |
int on; |
int on; |
int tt; |
int tt; |
extern int errno; |
extern int Post_debug; |
|
|
|
if ((char *)getenv("OXWEB_DEBUG") != NULL) { |
|
Post_debug = 1; |
|
} |
|
|
if (obj.tag != Sarray) { |
if (obj.tag != Sarray) { |
errorMsg1s("KsocketOpen([optional integer,optional string name])"); |
errorMsg1s("KsocketOpen([optional integer,optional string name])"); |
} |
} |
Line 55 struct object KsocketOpen(struct object obj) { |
|
Line 62 struct object KsocketOpen(struct object obj) { |
|
|
|
/* fprintf(stderr,"Hello from open.\n"); */ |
/* fprintf(stderr,"Hello from open.\n"); */ |
if ((myhost = gethostbyname(serverName)) == NULL) { |
if ((myhost = gethostbyname(serverName)) == NULL) { |
errorMsg1s("Bad server name."); |
perror("gethostbyname"); errorMsg1s("Bad server name."); |
} |
} |
bzero((char *)&me,sizeof(me)); |
bzero((char *)&me,sizeof(me)); |
me.sin_family = AF_INET; |
me.sin_family = AF_INET; |
Line 64 struct object KsocketOpen(struct object obj) { |
|
Line 71 struct object KsocketOpen(struct object obj) { |
|
&me.sin_addr,myhost->h_length); |
&me.sin_addr,myhost->h_length); |
|
|
if ((s_waiting = socket(AF_INET,SOCK_STREAM,0)) < 0) { |
if ((s_waiting = socket(AF_INET,SOCK_STREAM,0)) < 0) { |
errorMsg1s("Socket allocation is failed."); |
perror("socket"); errorMsg1s("Socket allocation is failed."); |
} |
} |
|
|
on=1; setsockopt(s_waiting,SOL_SOCKET,SO_REUSEADDR,&on,sizeof(on)); |
on=1; setsockopt(s_waiting,SOL_SOCKET,SO_REUSEADDR,&on,sizeof(on)); |
/* important */ |
/* important */ |
if (bind(s_waiting,(struct sockaddr *) &me,sizeof(me)) == -1) { |
if (bind(s_waiting,(struct sockaddr *) &me,sizeof(me)) == -1) { |
fprintf(stderr,"Bind error. Error no is %d. See /usr/include/sys/errno.h.\n",errno); |
fprintf(stderr,"Bind error. Error no is %d. See /usr/include/sys/errno.h.\n",errno); |
errorMsg1s("cannot bind"); |
perror("bind"); errorMsg1s("cannot bind"); |
} |
} |
|
|
tt = sizeof(me); |
tt = sizeof(me); |
if (getsockname(s_waiting,(struct sockaddr *)&me,&tt) < 0) { |
if (getsockname(s_waiting,(struct sockaddr *)&me,&tt) < 0) { |
fprintf(stderr,"getsockname error. Error no is %d. See /usr/include/sys/errno.h.\n",errno); |
fprintf(stderr,"getsockname error. Error no is %d. See /usr/include/sys/errno.h.\n",errno); |
errorMsg1s("cannot getsockname"); |
perror("getsockname"); errorMsg1s("cannot getsockname"); |
} |
} |
|
|
|
|
if (listen(s_waiting,MAX_LISTEN_QUEUE) < 0) { |
if (listen(s_waiting,MAX_LISTEN_QUEUE) < 0) { |
errorMsg1s("Listen failed"); |
perror("listen"); errorMsg1s("Listen failed"); |
} |
} |
/* |
/* |
fprintf(stderr,"Done the initialization. port =%d\n",ntohs(me.sin_port)); |
fprintf(stderr,"Done the initialization. port =%d\n",ntohs(me.sin_port)); |
Line 129 struct object KsocketConnect(struct object obj) { |
|
Line 136 struct object KsocketConnect(struct object obj) { |
|
|
|
|
|
if ((servhost = gethostbyname(serverName)) == NULL) { |
if ((servhost = gethostbyname(serverName)) == NULL) { |
errorMsg1s("bad server name.\n"); |
perror("gethostbyname"); errorMsg1s("bad server name.\n"); |
} |
} |
bzero((char *)&server,sizeof(server)); |
bzero((char *)&server,sizeof(server)); |
server.sin_family = AF_INET; |
server.sin_family = AF_INET; |
Line 138 struct object KsocketConnect(struct object obj) { |
|
Line 145 struct object KsocketConnect(struct object obj) { |
|
(char *)&server.sin_addr,servhost->h_length); |
(char *)&server.sin_addr,servhost->h_length); |
|
|
if ((socketid = socket(AF_INET,SOCK_STREAM,0)) <0) { |
if ((socketid = socket(AF_INET,SOCK_STREAM,0)) <0) { |
errorMsg1s("socket allocation is failed.\n"); |
perror("socket"); errorMsg1s("socket allocation is failed.\n"); |
} |
} |
if (!Quiet) { |
if (!Quiet) { |
fprintf(stderr,"Trying to connect port %d, ip=%x\n",ntohs(server.sin_port),server.sin_addr); |
fprintf(stderr,"Trying to connect port %d, ip=%x\n",ntohs(server.sin_port),server.sin_addr); |
} |
} |
if (connect(socketid,(struct sockaddr *)&server,sizeof(server)) == -1) { |
if (connect(socketid,(struct sockaddr *)&server,sizeof(server)) == -1) { |
errorMsg1s("cannot connect"); |
perror("connect"); errorMsg1s("cannot connect"); |
} |
} |
/* fprintf(stderr,"connected.\n"); */ |
/* fprintf(stderr,"connected.\n"); */ |
robj = newObjectArray(2); |
robj = newObjectArray(2); |
Line 156 struct object KsocketConnect(struct object obj) { |
|
Line 163 struct object KsocketConnect(struct object obj) { |
|
/* [ integer socketid ] |
/* [ integer socketid ] |
[ integer newsocketid ] */ |
[ integer newsocketid ] */ |
struct object KsocketAccept(struct object obj) { |
struct object KsocketAccept(struct object obj) { |
struct object obj1; |
struct object obj1 = OINIT; |
struct object obj2; |
struct object obj2 = OINIT; |
struct object robj; |
struct object robj = OINIT; |
int s, news; |
int s, news; |
|
|
if (obj.tag != Sarray) { |
if (obj.tag != Sarray) { |
Line 173 struct object KsocketAccept(struct object obj) { |
|
Line 180 struct object KsocketAccept(struct object obj) { |
|
} |
} |
s = KopInteger(obj1); |
s = KopInteger(obj1); |
if ((news = accept(s,NULL,NULL)) < 0) { |
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) { |
|
perror("accept"); errorMsg1s("Error in accept. Retry failed."); |
|
} |
} |
} |
if (close(s) < 0) { |
if (close(s) < 0) { |
errorMsg1s("Error in closing the old socket."); |
perror("close"); errorMsg1s("Error in closing the old socket."); |
} |
} |
robj = newObjectArray(1); |
robj = newObjectArray(1); |
putoa(robj,0,KpoInteger(news)); |
putoa(robj,0,KpoInteger(news)); |
Line 192 struct object KsocketAccept(struct object obj) { |
|
Line 203 struct object KsocketAccept(struct object obj) { |
|
.... |
.... |
*/ |
*/ |
struct object KsocketAccept2(struct object obj) { |
struct object KsocketAccept2(struct object obj) { |
struct object obj1; |
struct object obj1 = OINIT; |
struct object obj2; |
struct object obj2 = OINIT; |
struct object robj; |
struct object robj = OINIT; |
int s, news; |
int s, news; |
|
|
if (obj.tag != Sarray) { |
if (obj.tag != Sarray) { |
Line 209 struct object KsocketAccept2(struct object obj) { |
|
Line 220 struct object KsocketAccept2(struct object obj) { |
|
} |
} |
s = KopInteger(obj1); |
s = KopInteger(obj1); |
if ((news = accept(s,NULL,NULL)) < 0) { |
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) { |
|
perror("accept"); errorMsg1s("Error in accept. Retry failed."); |
|
} |
} |
} |
if (close(s) < 0) { |
if (close(s) < 0) { |
errorMsg1s("Error in closing the old socket."); |
perror("close"); errorMsg1s("Error in closing the old socket."); |
} |
} |
robj = newObjectArray(1); |
robj = newObjectArray(1); |
putoa(robj,0,KpoInteger(news)); |
putoa(robj,0,KpoInteger(news)); |
Line 222 struct object KsocketAccept2(struct object obj) { |
|
Line 237 struct object KsocketAccept2(struct object obj) { |
|
int KsocketSelect0(int fd,int t) { |
int KsocketSelect0(int fd,int t) { |
fd_set readfds; |
fd_set readfds; |
struct timeval timeout; |
struct timeval timeout; |
extern int errno; |
|
FD_ZERO(&readfds); |
FD_ZERO(&readfds); |
FD_SET(fd,&readfds); |
FD_SET(fd,&readfds); |
timeout.tv_sec = 0; |
timeout.tv_sec = 0; |
Line 231 int KsocketSelect0(int fd,int t) { |
|
Line 245 int KsocketSelect0(int fd,int t) { |
|
if (select(fd+1,&readfds,(fd_set *)NULL,(fd_set *)NULL,&timeout)<0) { |
if (select(fd+1,&readfds,(fd_set *)NULL,(fd_set *)NULL,&timeout)<0) { |
/* It must be fd+1 !, Not fd. */ |
/* It must be fd+1 !, Not fd. */ |
fprintf(stderr,"Select error. Error no is %d. See /usr/include/sys/errno.h.\n",errno); |
fprintf(stderr,"Select error. Error no is %d. See /usr/include/sys/errno.h.\n",errno); |
errorMsg1s("KsocketSelect0() : select failed."); |
perror("select"); errorMsg1s("KsocketSelect0() : select failed."); |
return(0); |
return(0); |
} |
} |
}else{ /* block */ |
}else{ /* block */ |
if (select(fd+1,&readfds,(fd_set *)NULL,(fd_set *)NULL,(struct timeval *)NULL)<0) { |
if (select(fd+1,&readfds,(fd_set *)NULL,(fd_set *)NULL,(struct timeval *)NULL)<0) { |
errorMsg1s("KsocketSelect0() : select failed."); |
perror("select"); errorMsg1s("KsocketSelect0() : select failed."); |
fprintf(stderr,"Select error. Error no is %d. See /usr/include/sys/errno.h.\n",errno); |
fprintf(stderr,"Select error. Error no is %d. See /usr/include/sys/errno.h.\n",errno); |
return(0); |
return(0); |
} |
} |
Line 249 int KsocketSelect0(int fd,int t) { |
|
Line 263 int KsocketSelect0(int fd,int t) { |
|
integer true or false |
integer true or false |
*/ |
*/ |
struct object KsocketSelect(struct object obj) { |
struct object KsocketSelect(struct object obj) { |
struct object robj; |
struct object robj = OINIT; |
struct object ob1; |
struct object ob1 = OINIT; |
struct object ob2; |
struct object ob2 = OINIT; |
if (obj.tag != Sarray) { |
if (obj.tag != Sarray) { |
errorMsg1s("KsocketSelect([ integer socketid optional integer timeout default 0]"); |
errorMsg1s("KsocketSelect([ integer socketid optional integer timeout default 0]"); |
} |
} |
Line 281 struct object KsocketSelectMulti(struct object obj) |
|
Line 295 struct object KsocketSelectMulti(struct object obj) |
|
[ result1, result2, ....] |
[ result1, result2, ....] |
*/ |
*/ |
{ |
{ |
struct object robj; |
struct object robj = OINIT; |
struct object ob1; |
struct object ob1 = OINIT; |
struct object ob2; |
struct object ob2 = OINIT; |
struct object ob3; |
struct object ob3 = OINIT; |
int size,i,fd,p,t; |
int size,i,fd,p,t; |
fd_set readfds; |
fd_set readfds; |
struct timeval timeout; |
struct timeval timeout; |
extern errno; |
|
if (obj.tag != Sarray) { |
if (obj.tag != Sarray) { |
errorMsg1s("KsocketSelectMulti([[sid1, sid2,...] optional integer timeout default 0]"); |
errorMsg1s("KsocketSelectMulti([[sid1, sid2,...] optional integer timeout default 0]"); |
} |
} |
Line 333 struct object KsocketSelectMulti(struct object obj) |
|
Line 346 struct object KsocketSelectMulti(struct object obj) |
|
if (select(fd+1,&readfds,(fd_set *)NULL,(fd_set *)NULL,&timeout)<0) { |
if (select(fd+1,&readfds,(fd_set *)NULL,(fd_set *)NULL,&timeout)<0) { |
/* It must be fd+1 !, Not fd. */ |
/* It must be fd+1 !, Not fd. */ |
fprintf(stderr,"Select error. Error no is %d. See /usr/include/sys/errno.h.\n",errno); |
fprintf(stderr,"Select error. Error no is %d. See /usr/include/sys/errno.h.\n",errno); |
errorMsg1s("KsocketSelectMulti() : select failed."); |
perror("select"); errorMsg1s("KsocketSelectMulti() : select failed."); |
} |
} |
}else{ /* block */ |
}else{ /* block */ |
if (select(fd+1,&readfds,(fd_set *)NULL,(fd_set *)NULL,(struct timeval *)NULL)<0) { |
if (select(fd+1,&readfds,(fd_set *)NULL,(fd_set *)NULL,(struct timeval *)NULL)<0) { |
fprintf(stderr,"Select error. Error no is %d. See /usr/include/sys/errno.h.\n",errno); |
fprintf(stderr,"Select error. Error no is %d. See /usr/include/sys/errno.h.\n",errno); |
errorMsg1s("KsocketSelectMulti() : (block) select failed."); |
perror("select"); errorMsg1s("KsocketSelectMulti() : (block) select failed."); |
} |
} |
} |
} |
robj = newObjectArray(size); |
robj = newObjectArray(size); |
Line 361 static char Data00[1024]; |
|
Line 374 static char Data00[1024]; |
|
string data |
string data |
*/ |
*/ |
struct object KsocketRead(struct object obj) { |
struct object KsocketRead(struct object obj) { |
struct object ob1; |
struct object ob1 = OINIT; |
struct object robj = NullObject; |
struct object robj = NullObject; |
static int datasize = 1024; |
static int datasize = 1024; |
static char *data = Data00; |
static char *data = Data00; |
Line 389 struct object KsocketRead(struct object obj) { |
|
Line 402 struct object KsocketRead(struct object obj) { |
|
if (datasize - totalsize > 0) { |
if (datasize - totalsize > 0) { |
n = read(socketid,data+totalsize,datasize-totalsize); |
n = read(socketid,data+totalsize,datasize-totalsize); |
if (n < 0) { |
if (n < 0) { |
|
perror("read"); |
errorMsg1s("Read error."); |
errorMsg1s("Read error."); |
} |
} |
if (n < datasize-totalsize) { |
if (n < datasize-totalsize) { |
Line 399 struct object KsocketRead(struct object obj) { |
|
Line 413 struct object KsocketRead(struct object obj) { |
|
errorMsg1s("Select returns 1, but there is no data to read."); |
errorMsg1s("Select returns 1, but there is no data to read."); |
} |
} |
}else { /* increase the datasize */ |
}else { /* increase the datasize */ |
tmp = (char *)GC_malloc(sizeof(char)*2*datasize); |
tmp = (char *)sGC_malloc(sizeof(char)*2*datasize); |
/*I should use GC_malloc_atomic and free after finishing this function?*/ |
/*I should use sGC_malloc_atomic and free after finishing this function?*/ |
if (tmp == (char *)NULL) errorMsg1s("Out of Memory."); |
if (tmp == (char *)NULL) errorMsg1s("Out of Memory."); |
bcopy(data,tmp,totalsize); |
bcopy(data,tmp,totalsize); |
data = tmp; |
data = tmp; |
Line 408 struct object KsocketRead(struct object obj) { |
|
Line 422 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."); |
if (r == (char *)NULL) errorMsg1s("Out of Memory."); |
bcopy(data,r,totalsize); |
bcopy(data,r,totalsize); |
r[totalsize] = 0; |
r[totalsize] = 0; |
Line 422 struct object KsocketRead(struct object obj) { |
|
Line 436 struct object KsocketRead(struct object obj) { |
|
/* [ integer socketid, string data ] |
/* [ integer socketid, string data ] |
integer */ |
integer */ |
struct object KsocketWrite(struct object obj) { |
struct object KsocketWrite(struct object obj) { |
struct object ob1; |
struct object ob1 = OINIT; |
struct object ob2; |
struct object ob2 = OINIT; |
int socketid; |
int socketid; |
int r; |
int r; |
|
int k,k0; |
|
char *s; |
if (obj.tag != Sarray) { |
if (obj.tag != Sarray) { |
errorMsg1s("KsocketWrite([integer socketid, string data])"); |
errorMsg1s("KsocketWrite([integer socketid, string data])"); |
} |
} |
Line 441 struct object KsocketWrite(struct object obj) { |
|
Line 457 struct object KsocketWrite(struct object obj) { |
|
if (ob2.tag != Sdollar) { |
if (ob2.tag != Sdollar) { |
errorMsg1s("KsocketWrite([integer socketid, string data]) : the second argument must be a string."); |
errorMsg1s("KsocketWrite([integer socketid, string data]) : the second argument must be a string."); |
} |
} |
r = write(socketid,KopString(ob2), strlen(KopString(ob2))); |
s = KopString(ob2); |
return(KpoInteger(r)); |
k0 = k = strlen(s); |
|
while (1) { |
|
r = write(socketid,s,k); |
|
if (r < 0) { |
|
perror("write"); errorMsg1s("KsocketWrite: write failed."); |
|
} |
|
if (r >= k) break; |
|
k -= r; |
|
s = &(s[r]); |
|
} |
|
return(KpoInteger(k0)); |
|
|
} |
} |
struct object KsocketClose(struct object obj) { |
struct object KsocketClose(struct object obj) { |
int socketid; |
int socketid; |
struct object ob1; |
struct object ob1 = OINIT; |
if (obj.tag != Sarray) { |
if (obj.tag != Sarray) { |
errorMsg1s("KsocketClose([ integer socketid ])"); |
errorMsg1s("KsocketClose([ integer socketid ])"); |
} |
} |
Line 474 struct object KsocketReadByte(struct object obj); |
|
Line 500 struct object KsocketReadByte(struct object obj); |
|
struct object KsocketWriteByte(struct object obj); |
struct object KsocketWriteByte(struct object obj); |
|
|
struct object KsocketReadByte(struct object obj) { |
struct object KsocketReadByte(struct object obj) { |
struct object ob1; |
struct object ob1 = OINIT; |
struct object robj = NullObject; |
struct object robj = NullObject; |
char data[2]; |
char data[2]; |
char *tmp; |
char *tmp; |
Line 498 struct object KsocketReadByte(struct object obj) { |
|
Line 524 struct object KsocketReadByte(struct object obj) { |
|
|
|
n = read(socketid,data,1); |
n = read(socketid,data,1); |
if (n < 0) { |
if (n < 0) { |
|
perror("read"); |
errorMsg1s("Read error."); |
errorMsg1s("Read error."); |
robj = KpoInteger(-1); |
robj = KpoInteger(-1); |
return(robj); |
return(robj); |
Line 514 struct object KsocketReadByte(struct object obj) { |
|
Line 541 struct object KsocketReadByte(struct object obj) { |
|
/* [ integer socketid, int ] |
/* [ integer socketid, int ] |
integer */ |
integer */ |
struct object KsocketWriteByte(struct object obj) { |
struct object KsocketWriteByte(struct object obj) { |
struct object ob1; |
struct object ob1 = OINIT; |
struct object ob2; |
struct object ob2 = OINIT; |
int socketid; |
int socketid; |
int r,i,n,kk,r0; |
int r,i,n,kk,r0; |
#define DATA_SIZE 1024 |
#define DATA_SIZE 1024 |
Line 538 struct object KsocketWriteByte(struct object obj) { |
|
Line 565 struct object KsocketWriteByte(struct object obj) { |
|
if (ob2.tag == Sinteger) { |
if (ob2.tag == Sinteger) { |
data[0] = KopInteger(ob2); |
data[0] = KopInteger(ob2); |
r = write(socketid,data, 1); |
r = write(socketid,data, 1); |
|
if (r < 0) { |
|
perror("write"); errorMsg1s("KsocketWriteByte: write error"); |
|
} |
}else{ |
}else{ |
n = getoaSize(ob2); kk = 0; r = 0; |
n = getoaSize(ob2); kk = 0; r = 0; |
for (i=0; i<n; i++) { |
for (i=0; i<n; i++) { |
if (getoa(ob2,i).tag != Sinteger) |
if (getoa(ob2,i).tag != Sinteger) |
errorMsg1s("KsocketWriteByte([integer socketid, int | array of int]) : elements of the second argument must be integers."); |
errorMsg1s("KsocketWriteByte([integer socketid, int | array of int]) : elements of the second argument must be integers."); |
data[kk] = KopInteger(getoa(ob2,i)); |
data[kk] = KopInteger(getoa(ob2,i)); |
kk++; |
kk++; |
if (kk >= DATA_SIZE) { |
if (kk >= DATA_SIZE) { |
r0 = write(socketid,data,kk); |
r0 = write(socketid,data,kk); |
if (r0 != kk) { |
if (r0 < 0) { perror("write"); errorMsg1s("write failed."); } |
fprintf(stderr,"Warning: Could not write to the socket.\n"); |
if (r0 != kk) { |
return(KpoInteger(r+r0)); |
fprintf(stderr,"Warning: Could not write to the socket.\n"); |
} |
return(KpoInteger(r+r0)); /* bug: we should retry. */ |
|
} |
r += r0; |
r += r0; |
kk = 0; |
kk = 0; |
} |
} |
} |
} |
if (kk > 0) { |
if (kk > 0) { |
r0 = write(socketid,data,kk); |
r0 = write(socketid,data,kk); |
|
if (r0 < 0) { perror("write"); errorMsg1s("write failed."); } |
if (r0 != kk) { |
if (r0 != kk) { |
fprintf(stderr,"Warning: Could not write to the socket.\n"); |
fprintf(stderr,"Warning: Could not write to the socket.\n"); |
return(KpoInteger(r+r0)); |
return(KpoInteger(r+r0)); |
} |
} |
r += r0; |
r += r0; |
} |
} |
Line 569 struct object KsocketWriteByte(struct object obj) { |
|
Line 601 struct object KsocketWriteByte(struct object obj) { |
|
|
|
struct object KsocketReadHTTP(struct object socketObj) { |
struct object KsocketReadHTTP(struct object socketObj) { |
/* Read until two empty line appears. */ |
/* Read until two empty line appears. */ |
struct object ob; |
struct object ob = OINIT; |
struct object ob1; |
struct object ob1 = OINIT; |
struct object nob; |
struct object nob = OINIT; |
char *s; |
char *s; |
char *sss; |
char *sss; |
char *tmp; |
char *tmp; |
Line 582 struct object KsocketReadHTTP(struct object socketObj) |
|
Line 614 struct object KsocketReadHTTP(struct object socketObj) |
|
int last; |
int last; |
int contentLength=-1; |
int contentLength=-1; |
int socketid; |
int socketid; |
|
extern int Post_debug; |
nob = NullObject; |
nob = NullObject; |
|
|
if (socketObj.tag != Sarray) { |
if (socketObj.tag != Sarray) { |
Line 630 struct object KsocketReadHTTP(struct object socketObj) |
|
Line 663 struct object KsocketReadHTTP(struct object socketObj) |
|
break; |
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) { |
if (strlen(s) == 0) { |
fprintf(stderr,"No data. Perhaps connection is closed by foreign host.\n"); |
fprintf(stderr,"No data. Perhaps connection is closed by foreign host.\n"); |
return nob; |
return nob; |
}else{ |
}else{ |
/* for debugging. */ |
/* for debugging. */ |
for (i=0; i<strlen(sss); i++) { |
if (Post_debug) { |
if ((sss[i] >= ' ') && (sss[i] < 0x7f)) { |
for (i=0; i<strlen(sss); i++) { |
fprintf(stderr,"%c",sss[i]); |
if ((sss[i] >= ' ') && (sss[i] < 0x7f)) { |
}else{ |
fprintf(stderr,"%c",sss[i]); |
fprintf(stderr,"(%3x)",sss[i]); |
}else{ |
if (sss[i] == 0xa) fprintf(stderr,"\n"); |
fprintf(stderr,"(%3x)",sss[i]); |
} |
if (sss[i] == 0xa) fprintf(stderr,"\n"); |
|
} |
|
|
|
} |
|
fprintf(stderr,"\n"); |
} |
} |
fprintf(stderr,"\n"); |
|
} |
} |
|
|
if (KsocketSelect0(socketid,-1) != 1) { |
if (KsocketSelect0(socketid,-1) != 1) { |
Line 665 struct object KsocketReadHTTP(struct object socketObj) |
|
Line 702 struct object KsocketReadHTTP(struct object socketObj) |
|
} |
} |
} |
} |
if (datasize-1 <= strlen(sss)+strlen(s)) { |
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."); |
if (tmp == (char *)NULL) errorMsg1s("Out of Memory."); |
strcpy(tmp,sss); |
strcpy(tmp,sss); |
strcat(tmp,s); |
strcat(tmp,s); |
Line 769 struct object KsocketGetHostName(void) { |
|
Line 806 struct object KsocketGetHostName(void) { |
|
if (gethostname(name,1023) != 0) { |
if (gethostname(name,1023) != 0) { |
return rob; |
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."); |
if (s == (char *)NULL) errorMsg1s("Out of Memory."); |
strcpy(s,name); |
strcpy(s,name); |
return(KpoString(s)); |
return(KpoString(s)); |