Reputation: 177
here is the program that I wrote to implement zero copy in a Qt application but getting some errors written below:
//client.h
#ifndef CLIENT1_H
#define CLIENT1_H
#include <QObject>
#include <QString>
#include <QtNetwork/QTcpSocket>
#include <QtNetwork/QtNetwork>
class Client: public QObject
{
Q_OBJECT
public:
Client(QObject* parent = 0);
~Client();
void start(QString address, quint16 port);
public slots:
void startTransfer();
private:
QTcpSocket client;
};
#endif // CLIENT1_H
//client.cpp
#include "client1.h"
#include <QtNetwork/QHostAddress>
#include <MSWSockDef.h>
#include <MSWSock.h>
Client::Client(QObject* parent): QObject(parent)
{
connect(&client, SIGNAL(connected()),
this, SLOT(startTransfer()));
}
Client::~Client()
{
client.close();
}
void Client::start(QString address, quint16 port)
{
QHostAddress addr(address);
client.connectToHost(addr, port);
}
void Client::startTransfer()
{
int TransmitFile( client,
hfile,
NULL,
NULL,
NULL,
NULL,
TF_USE_SYSTEM_THREAD
);
}
//main.cpp
#include <QCoreApplication>
#include <fstream>
#include <iostream>
#include "client1.h"
#include <QtNetwork/QtNetwork>
#include <Windows.h>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
HFILE hfile;
//Creates an instance of ofstream, and opens example.txt
ofstream a_file ( "example.txt" );
// Outputs to example.txt through a_file
a_file<<"This text will now be inside of example.txt";
// Close the file stream explicitly
hfile = a_file;
//a_file.close();
//hfile = a_file.open("example.txt");
//hfile = a_file.open("example.txt",ios_base::app);
Client client;
client.start("127.0.0.1", 8888);
return a.exec();
}
The errors are as below:
C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\MSWSock.
error: C2061: syntax error : identifier 'LPWSAMSG'
C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\MSWSock.h
error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\MSWSock.h
error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I know there are errors in transmitfile() api but those can be removed,what about the above errors?`enter code here?
Upvotes: 1
Views: 367
Reputation: 40512
Try to remove Mswsockdef.h
include.
...Mswsockdef.h header file which is automatically included in the Mswsock.h header file. The Mswsockdef.h header file should never be used directly.
Upvotes: 1
Reputation: 219
You would probably need to include Winsock2.h, can you try that?
Upvotes: 1