static void testRecvFail(CuTest *tc) { NTPSock*listenSock; NTPSock*connectSock; NTPSock*acceptSock; char buf[20]; int result; uint16_t port = 38712; //connect the sockets connectUtil(tc, &listenSock, &connectSock, &acceptSock, port); //close one socket NTPDisconnect(&connectSock); CuAssert(tc, "disconnect to NULL", connectSock==NULL); //try to recv() on the other socket result = NTPRecv(acceptSock, buf, sizeof(buf)); CuAssert(tc, "recv should fail", result<=0); //cleanup NTPDisconnect(&listenSock); NTPDisconnect(&acceptSock); CuAssert(tc, "disconnect NULL", listenSock==NULL); CuAssert(tc, "disconnect NULL", acceptSock==NULL); }
static void testSendFail(CuTest *tc) { NTPSock *listenSock; NTPSock *connectSock; NTPSock *acceptSock; char buf[] = "So remember, remember the Red River Valley"; int result; uint16_t port = 23551; //connect the sockets connectUtil(tc, &listenSock, &connectSock, &acceptSock, port); //close one socket NTPDisconnect(&acceptSock); CuAssert(tc, "disconnect to NULL", acceptSock==NULL); //try to send() on the other socket. Keep trying //because it doesn't always fail the first time. int i; for(i=0;i<20;i++) { result = NTPSend(connectSock, buf, NTPstrlen(buf)); } CuAssert(tc, "Send should fail", result<=0); //cleanup NTPDisconnect(&listenSock); NTPDisconnect(&connectSock); CuAssert(tc, "disconnect NULL", listenSock==NULL); CuAssert(tc, "disconnect NULL", acceptSock==NULL); }
void connect(TreeLinkNode *root) { if(root == nullptr) return; root->next = nullptr; connectUtil(root); return; }
void connectUtil(TreeLinkNode *root) { if(root == nullptr) return; if(root->left) { if(root->right) root->left->next = root->right; else root->left->next = getNext(root); } if(root->right) root->right->next = getNext(root); connectUtil(root->next); connectUtil(root->left); connectUtil(root->right); return; }