int count=0;
struct Unit {
- Unit(){}
- Unit(const Unit&) = delete;
- Unit(Unit&&) = default;
struct msghdr msgh;
struct iovec iov;
char cbuf[256];
- struct mmsghdr mmh;
};
- vector<Unit> units;
+ vector<unique_ptr<Unit> > units;
+ int ret;
for(const auto& p : *packets) {
count++;
- Unit u;
+ unique_ptr<Unit> u{new Unit()};
- fillMSGHdr(&u.msgh, &u.iov, u.cbuf, 0, (char*)&p[0], p.size(), &dest);
+ fillMSGHdr(&u->msgh, &u->iov, u->cbuf, 0, (char*)&p[0], p.size(), &dest);
units.emplace_back(std::move(u));
-
+
if(units.size()==burst) {
vector<struct mmsghdr> job;
for(auto& u : units) {
- job.push_back({u.msgh, 0});
+ job.push_back({u->msgh, 0});
+ }
+ if((ret=sendmmsg((*sockets)[count % sockets->size()]->getHandle(),
+ &job[0], job.size(), 0)) != job.size()) {
+ if(ret < 0)
+ unixDie("sendmmsg");
+ else
+ cerr<<"Sent out partial number of packets: "<<ret<<endl;
}
- sendmmsg((*sockets)[count % sockets->size()]->getHandle(),
- &job[0], job.size(), 0);
nanosleep(&nsec, 0);
units.clear();