Пример #1
0
std::unique_ptr<ExternalInterface::invoke_t>
ExternalInterface::ExternalEventCheck(int fd)
{
//    GNASH_REPORT_FUNCTION;
    
    std::unique_ptr<ExternalInterface::invoke_t> error;

    if (fd > 0) {
        int bytes = 0;
        ioctlSocket(fd, FIONREAD, &bytes);
        if (bytes == 0) {
            return error;
        }
        log_debug("There are %d bytes in the network buffer", bytes);
        std::unique_ptr<char[]> buffer(new char[bytes + 1]);
        // Since we know how bytes are in the network buffer, allocate
        // some memory to read the data.
        // terminate incase we want to treat the data like a string.
        buffer[bytes] = 0;
        const int ret = ::read(fd, buffer.get(), bytes);
        if (ret > 0) {
            return parseInvoke(std::string(buffer.get(), ret));
        }
    }

    return error;
}
Пример #2
0
std::string
GnashPluginScriptObject::readPlayer(int fd)
{
//    log_debug(__PRETTY_FUNCTION__);

    std::string empty;

    if (fd <= 0) {
        log_error("Invalid fd passed");
        return empty;
    }

    // Wait for some data from the player
    int bytes = 0;
    fd_set fdset;
    FD_ZERO(&fdset);
    FD_SET(fd, &fdset);
    struct timeval tval;
    tval.tv_sec = 2;
    tval.tv_usec = 0;
    // log_debug("Waiting for data... ");
    if (select(fd+1, &fdset, NULL, NULL, &tval)) {
        // log_debug("There is data in the network");
#ifndef _WIN32
        ioctl(fd, FIONREAD, &bytes);
#else
        ioctlSocket(fd, FIONREAD, &bytes);
#endif
    }

    // No data yet
    if (bytes == 0) {
        return empty;
    }

    log_debug("There are %d bytes in the network buffer", bytes);

    std::string buf(bytes, '\0');

    int ret = ::read(fd, &buf[0], bytes);
    if (ret <= 0) {
        return empty;
    }

    if (ret < bytes) {
        buf.resize(ret);
    }

    return buf;
}
Пример #3
0
std::string
ExternalInterface::readBrowser(int fd)
{
    std::string empty;
    fd_set fdset;
    struct timeval timeout;
    int fdstatus;
    int bytes = 0;

    // Wait for some data from the player
    FD_ZERO(&fdset);
    FD_SET(fd, &fdset);
    timeout.tv_sec = 10;
    timeout.tv_usec = 0;
    fdstatus = select(fd + 1, &fdset, nullptr, nullptr, &timeout);
    if (fdstatus == 0) {
        // Timed out, return no data
        log_error("Host container communication timed out\n");
        return empty;
    } else if(fdstatus < 0) {
        // select() failed, return no data
        log_error("select failed on host container communication: %s",
                  std::strerror(errno));
        return empty;
    }

    // Check for the size of available data
    ioctlSocket(fd, FIONREAD, &bytes);
    if (bytes == 0) {
        // No more data to read (end of stream, or stream error)
        return empty;
    }

    log_debug("There are %d bytes in the network buffer", bytes);

    std::string buf(bytes, '\0');

    const int ret = ::read(fd, &buf[0], bytes);
    if (ret <= 0) {
        return empty;
    }

    if (ret < bytes) {
        buf.resize(ret);
    }

    return buf;
}
Пример #4
0
std::string
GnashPluginScriptObject::readPlayer(int fd)
{
    std::string empty;

    if (fd <= 0) {
        log_error("Invalid fd passed");
        return empty;
    }

    // Wait for some data from the player
    int bytes = 0;

    pollfd pfds[1] = { pollfd() };
    pfds[0].fd = fd;
    pfds[0].events = POLLIN;

    int rv = poll(pfds, 1 /* arraySize */, 2000 /* ms */);

    // No data yet
    if (rv <= 0) {
        return empty;
    }

#ifndef _WIN32
    rv = ioctl(fd, FIONREAD, &bytes);
#else
    rv = ioctlSocket(fd, FIONREAD, &bytes);
#endif
    if (rv < 0) {
        log_error("FIONREAD ioctl failed, unable to get network buffer length");
        return empty;
    }
    log_debug("There are %d bytes in the network buffer", bytes);

    if (bytes <= 0) {
        return empty;
    }

    char buf[bytes];

    int ret = ::read(fd, buf, bytes);
    if (ret <= 0 || ret > bytes) {
        return empty;
    }

    return std::string(buf, ret);
}