-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIncoming.cpp
More file actions
48 lines (42 loc) · 1.11 KB
/
Incoming.cpp
File metadata and controls
48 lines (42 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "Incoming.h"
Incoming::Incoming(QQueue <struct Cell>*pool,QSemaphore *geneblocker)
{
genepool = pool;
genepoolblocker = geneblocker;
port = PORT;
server = new QTcpServer();
connect(server, SIGNAL(newConnection()),this, SLOT(accept()));
if(!server->listen(QHostAddress::Any,port)){
qDebug() << "could not open server port";
}
}
Incoming::~Incoming()
{
}
void Incoming::accept(){
QTcpSocket *connection = server->nextPendingConnection();
qDebug() << "looking at connection";
if(connection){
qDebug() << "received connection";
genepoolblocker->acquire(1);
quint32 number = 0;
qDebug() << "poolsize:" << genepool->size();
QByteArray block;
QDataStream out(&block,QIODevice::WriteOnly);
if(!genepool->isEmpty()){
number = 1;
qDebug() << number;
out << number;
struct Cell cell = genepool->dequeue();
qDebug() << out.writeRawData((char *)&cell,sizeof(struct Cell));
qDebug() << "sent one cell";
}else{
out << number;
}
connection->write(block);
connection->flush();
connection->waitForBytesWritten(-1);
connection->close();
genepoolblocker->release(1);
}
}