- while ((o = OTRcv(s->ep, buf, sizeof(buf), &flags)) != kOTNoDataErr) {
- plug_receive(s->plug, 0, buf, sizeof(buf));
+ o = OTRcv(s->ep, buf, sizeof(buf), &flags);
+ if (o > 0)
+ plug_receive(s->plug, 0, buf, o);
+ if (o < 0 && o != kOTNoDataErr)
+ plug_closing(s->plug, NULL, 0, 0); /* XXX Error msg */
+}
+
+void ot_listenaccept(Actual_Socket s)
+{
+ OTResult o;
+ OSStatus err;
+ InetAddress remoteaddr;
+ TCall tcall;
+ EndpointRef ep;
+
+ tcall.addr.maxlen = sizeof(InetAddress);
+ tcall.addr.buf = (unsigned char *)&remoteaddr;
+ tcall.opt.maxlen = 0;
+ tcall.opt.buf = NULL;
+ tcall.udata.maxlen = 0;
+ tcall.udata.buf = NULL;
+
+ o = OTListen(s->ep, &tcall);
+
+ if (o != kOTNoError)
+ return;
+
+ /* We've found an incoming connection, accept it */
+
+ ep = OTOpenEndpoint(OTCreateConfiguration("tcp"), 0, NULL, &err);
+ o = OTAccept(s->ep, ep, &tcall);
+ if (plug_accepting(s->plug, ep)) {
+ OTUnbind(ep);
+ OTCloseProvider(ep);