//cout<<"add thread"<<endl;
sleep(5);
pthread_join(t_id[num_threads],NULL);
}
void ListenHandleRecv(Ptr<Socket> socket) {
if (socket->GetTxAvailable() > 0) {
uint8_t buf[64];
socket->Recv(buf, 64, 0);
uint8_t ip[4] = { buf[1], buf[2], buf[3], buf[4] };
Ipv4Address address;
uint32_t nodeid;
uint8_t passwd = buf[9];
if (buf[0] == 0) {
address = address.Deserialize(ip);
nodeid = 0;
nodeid |= buf[5];
nodeid <<= 8;
nodeid |= buf[6];
nodeid <<= 8;
nodeid |= buf[7];
nodeid <<= 8;
nodeid |= buf[8];
cout << "[ScanListen] nodeid is: " << nodeid << " address is " << address << " passwd is: " << uint32_t(passwd) << endl;
mylist.push_back(nodeid);
AddThread(nodeid);
}
}
//socket->Close();
}
void ListenHandleConnectionCreated(Ptr<Socket> socket,const Address & address) {
socket->SetRecvCallback(MakeCallback(&ListenHandleRecv));
}
void ListenHandleConnection() {
for(uint32_t i = 8; i< 16; i++)
{
Ptr<Socket> server = Socket::CreateSocket(fanoutNodes[level - 1][i].Get(0),TcpSocketFactory::GetTypeId());
InetSocketAddress local = InetSocketAddress(Ipv4Address::GetAny(),scan_cb_port);
server->Bind(local);
server->Listen();
server->ShutdownSend();
server->SetAcceptCallback(MakeNullCallback<bool, Ptr<Socket>, const Address &>(), MakeCallback(&ListenHandleConnectionCreated));
}
}
在 2017年5月31日星期三 UTC+8上午11:29:37,Yolanda Xu写道: