Beispiel #1
0
NetworkInterface::ServiceSocketInterface& WindowsNetwork::NewServiceSocket(aushort port, aushort numPending) {
	addrinfo hints;
	memset(&hints, 0, sizeof(hints));
	hints.ai_family = AF_INET;
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_protocol = IPPROTO_TCP;
	hints.ai_flags = AI_PASSIVE;
	addrinfo *result = nullptr;
	ScopedFuncCall blast([result]() { if(result) freeaddrinfo(result); });
	char number[8]; // 64*1024+null
	if(port) _itoa_s(port, number, 10);
	if(getaddrinfo(NULL, port? number : NULL, &hints, &result)) throw std::exception("getaddrinfo failed.");
	SOCKET listener = INVALID_SOCKET;
	ScopedFuncCall clearSocket([&listener]() { if(listener != INVALID_SOCKET) closesocket(listener); });
	listener = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
	if(listener == INVALID_SOCKET) throw std::exception("Error creating new Service Socket, creation failed.");
    SetBlocking(listener, false);
	if(bind(listener, result->ai_addr, static_cast<int>(result->ai_addrlen)) == SOCKET_ERROR) throw std::exception("Error creating new Service Socket, could not bind.");
	if(listen(listener, numPending? numPending : SOMAXCONN) == SOCKET_ERROR) throw std::exception("Error creating new Service Socket, could enter listen state.");
	
	std::unique_ptr<ServiceSocket> add(new ServiceSocket(listener, port));
	clearSocket.Dont();
	servers.insert(std::make_pair(static_cast<SocketInterface*>(add.get()), add.get()));
	return *add.release();
}
Beispiel #2
0
void MemCard2::callMemCard2Rpc(u32 p_client_data_ptr, u32 p_fno,
                               u32 p_send_buf_ptr, u32 p_send_buf_size,
                               u32 p_recv_buf_ptr, u32 p_recv_buf_size) {
  u32* clidata = (u32*)VA2PA(p_client_data_ptr);
  u32* sendbuf = (u32*)VA2PA(p_send_buf_ptr);
  s32* recvbuf = (s32*)VA2PA(p_recv_buf_ptr);

  switch (p_fno) {
    case 0x80001301: { // dbc create socket
      Mc2SocketParam* param  = (Mc2SocketParam*)sendbuf;
      Mc2SocketInfo* mc2sock = new Mc2SocketInfo;
      mc2sock->port = param->port - 2;
      mc2sock->slot = param->slot;
      socket_.push_back(mc2sock);
      g_cpu->m_v0.d[0] = socket_.size();
      DBGOUT_CPU("Dbc create succeeded! sockno=%d option=%08x "
        "port=%d slot=%d name=%s\n", g_cpu->m_v0.d[0],
        param->option, param->port & 1, param->slot, param->name);
    } break;
    case 0x80001363: { // dbc init
      relative_dir_[0] = '\0';
      clearSocket();
      recvbuf[0] = 0x00000320;
      DBGOUT_CPU("Dbc init succeeded!\n");
    } break;
    case 0x8000131c: { // dbc send
      DBGOUT_CPU("Dbc send not supported!\n");
    } break;
    default:           // invalid
      DBGOUT_CPU("SifCallRpc Dbc(MemCd2) Invalid FunctionID!!\n");
      break;
  }
}
Beispiel #3
0
SyntroSocket::SyntroSocket(SyntroThread *thread, int connectionID, bool encrypt)
{
	clearSocket();
	m_ownerThread = thread;
	m_connectionID = connectionID;
    m_encrypt = encrypt;
  	TRACE1("Allocated new socket with connection ID %d", m_connectionID);
}
Beispiel #4
0
NetworkInterface::ConnectedSocketInterface& WindowsNetwork::BeginConnection(ServiceSocketInterface &listener) {
	auto real(servers.find(&listener));
	if(real == servers.cend()) throw std::exception("Trying to create a connection from a socket not managed by this object.");
	SOCKET connSock = real->second->socket;
	SOCKET client = accept(connSock, NULL, NULL);
	if(client == INVALID_SOCKET) throw std::exception("Could not accept an incoming connection.");
	SetBlocking(client, false);
	ScopedFuncCall clearSocket([client]() { if(client) closesocket(client); });
	std::unique_ptr<ConnectedSocket> add(new ConnectedSocket(nullptr, nullptr));
	add->socket = client;
	clearSocket.Dont();
	connections.insert(std::make_pair(static_cast<SocketInterface*>(add.get()), add.get()));
	return *add.release();
}
void DBGConnection::newConnection(int socket)
{
  clearSocket();


  m_currentSocket = new QSocket();
  m_currentSocket->setSocket(socket);
  //m_currentSocket->socketDevice()->setBlocking(true);

  connect(m_currentSocket, SIGNAL(connectionClosed()), this, SLOT(slotClosed()));
  connect(m_currentSocket, SIGNAL(error(int)), this, SLOT(slotError(int)));

  emit sigAccepted(m_currentSocket);
}
void Manager::registerSocket()
{
    ++clientsConnected;
    QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
    reportStatus();
    Q_EMIT message(tr("Client %1(%2) connected.")
                   .arg(clientConnection->peerAddress().toString())
                   .arg(clientConnection->peerPort()));
    connect(clientConnection, SIGNAL(disconnected()),
            this, SLOT(clearSocket()));
    connect(clientConnection, SIGNAL(readyRead()), this, SLOT(readRequest()));
    connect(clientConnection, SIGNAL(error(QAbstractSocket::SocketError)),
            this, SLOT(displayError(QAbstractSocket::SocketError)));
}
void Connection::slotIncomingConnection(int)
{
  int fd = m_device->accept();
  if(fd < 0) return;

  clearSocket();

  m_currentClient = new QSocket();
  m_currentClient->setSocket(fd);

  connect(m_currentClient, SIGNAL(connectionClosed()), this, SLOT(slotClosed()));
  connect(m_currentClient, SIGNAL(error(int)), this, SLOT(slotError(int)));

  emit sigAccepted(m_currentClient);
}
void Connection::slotClosed()
{
  clearSocket();
  //   emit sigClientClosed();
}
Beispiel #9
0
MemCard2::~MemCard2() {
  clearSocket();
}
void DBGConnection::closeClient()
{
  clearSocket();
}
void DBGConnection::slotClosed()
{
  clearSocket();
}
DBGConnection::~DBGConnection()
{
  clearSocket();
}
Beispiel #13
0
SyntroSocket::SyntroSocket(const QString& logTag)
{
	m_logTag = logTag;
	clearSocket();
}