2019-04-27 19:12:09 +00:00
|
|
|
#ifndef WINGS_SOCKET_H
|
|
|
|
#define WINGS_SOCKET_H
|
2019-04-29 05:55:02 +00:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <netinet/in.h>
|
2019-04-27 19:12:09 +00:00
|
|
|
#include <dart_api.h>
|
2019-04-29 05:55:02 +00:00
|
|
|
#include <dart_native_api.h>
|
|
|
|
#include <memory>
|
|
|
|
#include <thread>
|
2019-04-27 19:12:09 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace wings
|
|
|
|
{
|
|
|
|
struct WingsSocketInfo
|
|
|
|
{
|
2019-04-29 05:55:02 +00:00
|
|
|
const char *address;
|
|
|
|
uint64_t port;
|
|
|
|
bool shared;
|
|
|
|
uint64_t backlog;
|
|
|
|
bool v6Only;
|
|
|
|
Dart_Handle sendPortHandle;
|
|
|
|
bool operator==(const WingsSocketInfo &other) const;
|
2019-04-27 19:12:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class WingsSocket
|
|
|
|
{
|
2019-04-29 05:55:02 +00:00
|
|
|
public:
|
2019-05-01 01:33:46 +00:00
|
|
|
WingsSocket(sa_family_t family, int sockfd, const WingsSocketInfo &info);
|
2019-04-29 05:55:02 +00:00
|
|
|
void incrRef(Dart_Port port);
|
|
|
|
const WingsSocketInfo &getInfo() const;
|
|
|
|
void start(Dart_NativeArguments arguments);
|
2019-05-01 01:33:46 +00:00
|
|
|
int getFD() const;
|
|
|
|
sa_family_t getFamily() const;
|
2019-04-27 19:12:09 +00:00
|
|
|
|
2019-04-29 05:55:02 +00:00
|
|
|
private:
|
|
|
|
static void threadCallback(Dart_Port dest_port_id, Dart_CObject *message);
|
|
|
|
WingsSocketInfo info;
|
|
|
|
int sockfd;
|
|
|
|
int refCount;
|
2019-05-01 01:33:46 +00:00
|
|
|
sa_family_t family;
|
2019-04-29 05:55:02 +00:00
|
|
|
std::unique_ptr<std::thread> workerThread;
|
|
|
|
std::vector<Dart_Port> sendPorts;
|
2019-04-27 19:12:09 +00:00
|
|
|
};
|
|
|
|
|
2019-04-29 05:55:02 +00:00
|
|
|
extern std::vector<WingsSocket *> globalSocketList;
|
2019-04-27 19:12:09 +00:00
|
|
|
} // namespace wings
|
|
|
|
|
|
|
|
#endif
|