main(int argc, char *argv[]) { struct sock* tx = udptx(GROUP, PORT) ; struct sock* rx = udprx(GROUP, PORT); uint64_t min=-1; int n; while (1) { uint64_t now = mach_absolute_time(); sendx(tx, (char*) &now, 8) ; //printf("<< %" PRId64 "\n", now) ; uint64_t then; receive(rx, (char*) &then, 8); uint64_t elapsed = mach_absolute_time() - then; if (min == -1 || elapsed < min) { min = elapsed; } //printf(">> %" PRId64 "\n", then) ; printf("%" PRId64 "\t(%" PRId64 ")\n", elapsed, min) ; sleep(1); } }
/* * Internal character-adder. It tries to keep the number of sendx() * calls down by looking at each character but only doing the output * when it has to escape something; ordinary text gets saved up in * chunks the start of which is indicated by *breaker. * c is the character, next points to the UTF8 representing the next * lastsP indirectly points to the UTF8 representing the * character, breakerP* indirectly points to the last place genx * changed the UTF8, e.g. by escaping a '<' */ static genxStatus addChar(genxWriter w, int c, constUtf8 next, constUtf8 * lastsP, constUtf8 * breakerP) { if (c == -1) return GENX_BAD_UTF8; if (!isXMLChar(w, c)) return GENX_NON_XML_CHARACTER; switch(c) { case 0xd: if ((w->status = sendxBounded(w, *breakerP, *lastsP)) != GENX_SUCCESS) return w->status; *breakerP = next; sendx(w, (utf8) "
"); break; case '<': if ((w->status = sendxBounded(w, *breakerP, *lastsP)) != GENX_SUCCESS) return w->status; *breakerP = next; sendx(w, (utf8) "<"); break; case '&': if ((w->status = sendxBounded(w, *breakerP, *lastsP)) != GENX_SUCCESS) return w->status; *breakerP = next; sendx(w, (utf8) "&"); break; case '>': if ((w->status = sendxBounded(w, *breakerP, *lastsP)) != GENX_SUCCESS) return w->status; *breakerP = next; sendx(w, (utf8) ">"); break; default: break; } *lastsP = next; return GENX_SUCCESS; }
int mem_to_net(int fd,int *buff,int protocol) { int rows,len,total; int i;Triple *Qson; char dest[20]; char * key_value; Qson = (Triple *) (buff+2); sendx(fd,buff,8,0); rows = Qson[0].pointer; total = 0; for(i=0;i<rows;i++) { key_value = Qson[i].key; sscanf(key_value,"%4d",&len); sprintf(dest,"%c%3d%4d",Qson[i].link,Qson[i].pointer,len); sendx(fd,dest,8,0); if(protocol = Qson_IO) { sendx(fd,key_value+4,len/4,0); if (total = (len & 0x3)) sendx(fd,"___",4-total,0); // keep at four byte boudary } else sendx(fd,key_value+4,len,0); DBG_printf("MN%s%c%3d%\n",key_value,Qson->link,Qson->pointer); } closesocketx(fd); return 0; }
JNIEXPORT jint JNICALL Java_UDPJni_sendx (JNIEnv *env, jobject self, jlong ss, jobject buf, jint len) { char* buf2 = (char*)(*env)->GetDirectBufferAddress(env, buf); return sendx((struct sock*) ss, buf2, len) ; }