int adhocSync(void) { int size = 0; int retry = 60; if (Server) { while (retry--) { adhocSend(adhoc_work, 1, ADHOC_DATATYPE_SYNC); if (adhocRecv(adhoc_work, 1000000, ADHOC_DATATYPE_SYNC) == 1) goto check_packet; } } else { while (retry--) { if (adhocRecv(adhoc_work, 1000000, ADHOC_DATATYPE_SYNC) == 1) { adhocSend(adhoc_work, 1, ADHOC_DATATYPE_SYNC); goto check_packet; } } } return -1; check_packet: while (1) { pdpStatStruct pdpStat; size = sizeof(pdpStat); if (sceNetAdhocGetPdpStat(&size, &pdpStat) >= 0) { // 余分なパケットを破棄 if (pdpStat.rcvdData == ADHOC_DATASIZE_SYNC) adhocRecv(adhoc_work, 0, ADHOC_DATATYPE_SYNC); else break; } if (Loop != LOOP_EXEC) return 0; sceKernelDelayThread(100); } return 0; }
// Used to receive data and then send an ack int adhocRecvSendAck(void *buffer, unsigned int *length) { int temp=1; int err=0; int tempLen = *length; int rcvdCount = 0; do { if(tempLen > 0x400) { tempLen = 0x400; } err = adhocRecvBlocked(buffer, length,-1); if(err < 0) return err; err = adhocSend(&temp, 1); rcvdCount += 0x400; buffer += 0x400; tempLen = length - rcvdCount; } while(rcvdCount < *length); // wait for an ack return err; }
// Used to send the data and wait for an ack int adhocSendRecvAck(void *buffer, int length) { int err=0; int recvTemp=0; int recvLen=1; int tempLen = length; int sentCount = 0; do { if(tempLen > 0x400) { tempLen = 0x400; } err = adhocSend(buffer, tempLen); if(err < 0) return err; // wait for an ack err = adhocRecvBlocked(&recvTemp, &recvLen,-1); if(err < 0) { pspDebugScreenInit(); printf("err=%x\n", err); return err; } buffer += 0x400; sentCount += 0x400; tempLen = length - sentCount; } while(sentCount < length); return err; }
int adhocRecvSendAck(void *buffer, int length, int timeout, int type) { int temp_length = length; int rcvd_length = 0; int error = 0; unsigned char *buf = (unsigned char *)buffer; do { if (temp_length > ADHOC_BUFFER_SIZE - 1) temp_length = ADHOC_BUFFER_SIZE - 1; if ((error = adhocRecv(buf, timeout, type)) != temp_length) return error; *(int *)adhoc_work = rcvd_length + temp_length; adhocSend(adhoc_work, 4, ADHOC_DATATYPE_ACK); buf += temp_length; rcvd_length += temp_length; temp_length = length - rcvd_length; } while (rcvd_length < length); return rcvd_length; }
int adhocSendRecvAck(void *buffer, int length, int timeout, int type) { int temp_length = length; int sent_length = 0; int error = 0; unsigned char *buf = (unsigned char *)buffer; do { if (temp_length > ADHOC_BUFFER_SIZE - 1) temp_length = ADHOC_BUFFER_SIZE - 1; adhocSend(buf, temp_length, type); if ((error = adhocRecv(adhoc_work, timeout, ADHOC_DATATYPE_ACK)) != 4) return error; if (*(int *)adhoc_work != sent_length + temp_length) return -1; buf += temp_length; sent_length += temp_length; temp_length = length - sent_length; } while (sent_length < length); return sent_length; }