7 typedef struct SunMsgUdp SunMsgUdp;
14 typedef struct Arg Arg;
25 UdpMaxRead = 65536+Udphdrsize
38 buf = emalloc(UdpMaxRead);
39 while((n = read(arg.fd, buf, UdpMaxRead)) > 0){
41 fprint(2, "udp got %d (%d)\n", n, Udphdrsize);
42 msg = emalloc(sizeof(SunMsgUdp));
43 memmove(&msg->udp, buf, Udphdrsize);
44 msg->msg.data = emalloc(n);
45 msg->msg.count = n-Udphdrsize;
46 memmove(msg->msg.data, buf+Udphdrsize, n-Udphdrsize);
47 memmove(&msg->udp, buf, Udphdrsize);
48 msg->msg.creply = arg.creply;
50 fprint(2, "message %p count %d\n", msg, msg->msg.count);
51 sendp(arg.srv->crequest, msg);
64 buf = emalloc(UdpMaxRead);
65 while((msg = recvp(arg.creply)) != nil){
66 memmove(buf+Udphdrsize, msg->msg.data, msg->msg.count);
67 memmove(buf, &msg->udp, Udphdrsize);
68 msg->msg.count += Udphdrsize;
69 if(write(arg.fd, buf, msg->msg.count) != msg->msg.count)
70 fprint(2, "udpWrite: %r\n");
77 sunSrvUdp(SunSrv *srv, char *address)
80 char adir[40], data[60];
83 acfd = announce(address, adir);
86 if(write(acfd, "headers", 7) < 0){
87 werrstr("setting headers: %r");
91 snprint(data, sizeof data, "%s/data", adir);
92 if((fd = open(data, ORDWR)) < 0){
93 werrstr("open %s: %r", data);
99 arg = emalloc(sizeof(Arg));
102 arg->creply = chancreate(sizeof(SunMsg*), 10);
103 arg->csync = chancreate(sizeof(void*), 10);
105 proccreate(sunUdpRead, arg, SunStackSize);
106 proccreate(sunUdpWrite, arg, SunStackSize);
109 chanfree(arg->csync);