Ok, so I changed everything to what follows. WAPUniverse replies back to the
server fine, but my biggest problem is my weakness, I cannot get the data to
reassemble properly. Please help me with that. The areas that I need help at
are denoted with a "// <=".
Thanks,
Donald
typedef struct SARType {
int pos; // Packet position, so we can receive out of order packets?
Boolean last; // Tells if it is the last packet
char *data; // The data
UInt32 size; // length of data
struct SARType *next; // More packets
} SARType;
typedef SARType *SARPtr;
SARPtr g->segment; // not actually defined like this, but just to show its
value
Int16 WspGetReply(Int16 sock, char *buf, Int16 buflen, UInt32
maxTimer,GlobalsType *g)
{
Int16 ret;
unsigned char rep[500];
int j = 0;
UInt32 waitTimer;
char *SARbuf;
int s = 0, t = 0;
file://SARbuf = NULL;
AppNetTimeout = 4 * SysTicksPerSecond();
// please don't turn me off now
EvtResetAutoOffTimer();
file://SARbuf = Malloc(DEF_RECEIVE_BUF+1);
file://ErrFatalDisplayIf(!SARbuf, "Malloc failed");
for(;;) {
start:
file://if (g->conn.connectionType == 'O') {
// ret = recv(sock,SARbuf,buflen,0);
file://} else {
ret = recv(sock,buf,buflen,0);
file://}
if ((errno==netErrTimeout) && ( TimGetTicks() < maxTimer ) ) {
return(0);
}
if (ret <= 0) {
g->progress= 0;
showProgress2(g);
g->state = BS_IDLE;
SetFieldFromStr2("WAPUniverse",fieldTitle);
if (ret == 0) {
MyErrorFunc2("Could not receive data from server. Connection closed
by remote host.","Receive");
return(-1);//ret = -1;
break;
}
MyErrorFunc2("\nCould not receive data from the
server.\nReason:\n",WspHostErrStr());
if (g->conn.connectionType == 'O') {
WTPAbort (sock, g);
}
if (errno == ENOMEM) {
MyErrorFunc2("ENOMEM","");
}
ret = -10;
break;
} else {
if (g->conn.connectionType == 'O') {
switch ((buf[0] & 0x78) >> 3) {
case WTP_Result:
switch ((buf[0] & 0x07) >> 1)
case 0x03:// SAR Not supported
case 0x01:// End of transmission
WTPAck(sock, g);
break;
case 0x00:// Not Last
/*s += ret;
for(j=0;j<(ret);j++)
SARbuf[j] = buf[j];*/
SARaddSegment(0, false, buf, (UInt32) ret, 1, g);
goto start;
break;
}
break;
case WTP_SAR_Result:
t++;
file://MemPtrResize (SARbuf, s);
file://StrCopy(buf+s, SARbuf+4);
/*for(j=0;j<(ret-4);j++)
SARbuf[j+s] = buf[j+4];
s += (ret-4);*/
switch ((buf[0] & 0x07) >> 1)
case 0x02: file://Last packet of group
SARaddSegment((int) buf[4], false, buf, (UInt32) (ret-4), 2, g);
SARGrpWTPAck(sock, t, g);
goto start;
break;
case 0x01: // End of transmission
SARaddSegment((int) buf[4], true, buf, (UInt32) (ret-4), 2, g);
SARWTPAck(sock, t, g);
SARreassemble(buf, buflen, g);
SARdeleteData(g);
break;
case 0x00: // Not Last
SARaddSegment((int) buf[4], false, buf, (UInt32) (ret-4), 2, g);
goto start;
break;
}
break;
case WTP_Ack:
file://Some gateways are too concerned and send Ack after just about
anything we send, so
file://we must learn to ignore unwanted Ack's
ret = WspGetReply(sock,buf,buflen,maxTimer,g);
return(ret);
break;
case WTP_Abort:
MyErrorFunc2("Could not receive data from server. Remote host sent
Abort.","Receive");
return(-20);
break;
default:
WTPAck(sock, g);
break;
}
break;
}
}
break;
}
file://Free(SARbuf);
return(ret);
}
Boolean SARaddSegment(int pos, Boolean last, char *data, UInt32 size, int
type, GlobalsType *g)
{
SARPtr tmp, sar;
int j = 0;
/*sar= g->segment;
while(sar != NULL)
{
if (pos == sar->pos)
{
return(false); // We already added this segment, I hope...
}
sar = sar->next;
}*/
tmp = Malloc (sizeof(SARType));
MemSet(tmp,sizeof(SARType),0);
ErrFatalDisplayIf (!tmp, "Malloc Failed");
tmp->pos = pos;
tmp->last = last;
tmp->size = size;
tmp->data = Malloc(size+1);
ErrFatalDisplayIf (!tmp->data, "Malloc Failed");
file://for (j=0;j<(size);j++)
// tmp->data[j] = data[j];
if (type == 2)
gstrcopy(tmp->data, data+4); // <=
else
gstrcopy(tmp->data, data); // <=
tmp->next = g->segment;
g->segment = tmp;
return(true);
}
Boolean SARreassemble(char *buf, Int16 buflen, GlobalsType *g)
{
SARPtr tmp;
int o = 0, j = 0;
UInt32 offset=0;
tmp = g->segment;
while((tmp != NULL) && (tmp->last != true))
if(tmp->pos == o){
if (MemPtrSize(buf) < (offset+tmp->size))
MemPtrResize(buf, offset+tmp->size);
file://StrCopy(buf+offset, tmp->data);
file://for (j=0;j<(offset+tmp->size);j++)
// buf[j+offset] = tmp->data[j];
gstrcopy(buf+offset, tmp->data); // <=
offset += tmp->size;
o++; // increase offeset
}
tmp=tmp->next;
}
}
Boolean SARdeleteData(GlobalsType *g)
{
SARPtr tmp;
while(g->segment != NULL){
tmp = g->segment;
g->segment = g->segment->next;
tmp->pos = 0;
tmp->size = 0;
tmp->last = false;
if(tmp->data)
Free(tmp->data);
Free(tmp);
}
return(true);
}
char *
gstrcopy(char *dst, const char *src)
{
char *tmp=dst;
if ( dst==NULL || src==NULL)
return NULL;
while (*src)
*tmp++ = *src++;
*tmp=0;
return(dst);
}
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/