-
Notifications
You must be signed in to change notification settings - Fork 26
/
mytcpsocket.h
50 lines (43 loc) · 1.06 KB
/
mytcpsocket.h
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
49
50
#ifndef MYTCPSOCKET_H
#define MYTCPSOCKET_H
#include <QThread>
#include <QTcpSocket>
#include <QMutex>
#include "netheader.h"
#ifndef MB
#define MB (1024 * 1024)
#endif
typedef unsigned char uchar;
class MyTcpSocket: public QThread
{
Q_OBJECT
public:
~MyTcpSocket();
MyTcpSocket(QObject *par=NULL);
bool connectToServer(QString, QString, QIODevice::OpenModeFlag);
QString errorString();
void disconnectFromHost();
quint32 getlocalip();
private:
void run() override;
qint64 readn(char *, quint64, int);
QTcpSocket *_socktcp;
QThread *_sockThread;
uchar *sendbuf;
uchar* recvbuf;
quint64 hasrecvive;
QMutex m_lock;
volatile bool m_isCanRun;
private slots:
bool connectServer(QString, QString, QIODevice::OpenModeFlag);
void sendData(MESG *);
void closeSocket();
public slots:
void recvFromSocket();
void stopImmediately();
void errorDetect(QAbstractSocket::SocketError error);
signals:
void socketerror(QAbstractSocket::SocketError);
void sendTextOver();
};
#endif // MYTCPSOCKET_H