/**
 **************************************************************************
 *
 * \brief Process the "post" command.
 *
 **************************************************************************
 */
static bool
ProcessCmdPost(int sd,        // IN
               char *data,    // IN
               int dataSize)  // IN
{
    MsgHdr req, reply;

    memset(&req, 0, sizeof req);
    req.type     = MSG_POST;
    req.dataSize = dataSize;
    
    if (WriteFully(sd, &req, sizeof req) <= 0) {
        return false;
    }
    if (WriteFully(sd, data, dataSize) <= 0) {
        return false;
    }

    if (ReadFully(sd, &reply, sizeof reply) <= 0) {
        return false;
    }
    if (reply.type != MSG_STATUS) {
        Error("Unexpected reply message type %d\n", reply.type);
        return false;
    }
    return false;
}
/**
 **************************************************************************
 *
 * \brief Process the "show" command.
 *
 **************************************************************************
 */
static bool
ProcessCmdShow(int sd,        // IN
               char *data,    // IN
               int dataSize)  // IN
{
    MsgHdr req, reply;

    memset(&req, 0, sizeof req);
    req.type = MSG_SHOW;
    
    if (WriteFully(sd, &req, sizeof req) <= 0) {
        return false;
    }

    if (ReadFully(sd, &reply, sizeof reply) <= 0) {
        return false;
    }
    if (reply.type != MSG_BOARD) {
        Error("Unexpected reply message type %d\n", reply.type);
        return false;
    }

    while (reply.dataSize > 0) {
        char ch;
        if (ReadFully(sd, &ch, sizeof ch) <= 0) {
            return false;
        }
        printf("%c", ch);
        reply.dataSize--;
    }
    return false;
}
static void LoadFirmware(const Uevent& uevent, const std::string& root, int fw_fd, size_t fw_size,
                         int loading_fd, int data_fd) {
    // Start transfer.
    WriteFully(loading_fd, "1", 1);

    // Copy the firmware.
    int rc = sendfile(data_fd, fw_fd, nullptr, fw_size);
    if (rc == -1) {
        PLOG(ERROR) << "firmware: sendfile failed { '" << root << "', '" << uevent.firmware
                    << "' }";
    }

    // Tell the firmware whether to abort or commit.
    const char* response = (rc != -1) ? "0" : "-1";
    WriteFully(loading_fd, response, strlen(response));
}
示例#4
0
/*----------------------------------------------------------------------
|   NPT_OutputStream::WriteLine
+---------------------------------------------------------------------*/
NPT_Result
NPT_OutputStream::WriteLine(const char* buffer)
{
    NPT_CHECK(WriteString(buffer));
    NPT_CHECK(WriteFully((const void*)"\r\n", 2));

    return NPT_SUCCESS;
}
示例#5
0
void notifyHostBootComplete() {
   if (s_QemuMiscPipe < 0) {
        s_QemuMiscPipe = qemu_pipe_open(QEMU_MISC_PIPE);
        if (s_QemuMiscPipe < 0) {
            ALOGE("failed to open %s", QEMU_MISC_PIPE);
            return;
        }
    }
    char set[] = "bootcomplete";
    int pipe_command_length = sizeof(set);
    WriteFully(s_QemuMiscPipe, &pipe_command_length, sizeof(pipe_command_length));
    WriteFully(s_QemuMiscPipe, set, pipe_command_length);
    ReadFully(s_QemuMiscPipe, &pipe_command_length, sizeof(pipe_command_length));
    if (pipe_command_length > sizeof(set) || pipe_command_length <= 0)
        return;
    ReadFully(s_QemuMiscPipe, set, pipe_command_length);
}
status_t PrivacyBuffer::flush(int fd) {
    status_t err = NO_ERROR;
    EncodedBuffer::iterator iter = size() == mData.size() ? mData : mProto.data();
    while (iter.readBuffer() != NULL) {
        err = WriteFully(fd, iter.readBuffer(), iter.currentToRead()) ? NO_ERROR : -errno;
        iter.rp()->move(iter.currentToRead());
        if (err != NO_ERROR) return err;
    }
    return NO_ERROR;
}
NS_IMETHODIMP
nsBinaryOutputStream::WriteStringZ(const char *aString)
{
    PRUint32 length;
    nsresult rv;

    length = strlen(aString);
    rv = Write32(length);
    if (NS_FAILED(rv)) return rv;
    return WriteFully(aString, length);
}
示例#8
0
/*----------------------------------------------------------------------
|   NPT_OutputStream::WriteString
+---------------------------------------------------------------------*/
NPT_Result
NPT_OutputStream::WriteString(const char* buffer)
{
    // shortcut
    NPT_Size string_length;
    if (buffer == NULL || (string_length = NPT_StringLength(buffer)) == 0) {
        return NPT_SUCCESS;
    }

    // write the string
    return WriteFully((const void*)buffer, string_length);
}
status_t HeaderSection::Execute(ReportRequestSet* requests) const {
    for (ReportRequestSet::iterator it = requests->begin(); it != requests->end(); it++) {
        const sp<ReportRequest> request = *it;
        const vector<vector<uint8_t>>& headers = request->args.headers();

        for (vector<vector<uint8_t>>::const_iterator buf = headers.begin(); buf != headers.end();
             buf++) {
            if (buf->empty()) continue;

            // So the idea is only requests with negative fd are written to dropbox file.
            int fd = request->fd >= 0 ? request->fd : requests->mainFd();
            write_section_header(fd, id, buf->size());
            WriteFully(fd, (uint8_t const*)buf->data(), buf->size());
            // If there was an error now, there will be an error later and we will remove
            // it from the list then.
        }
    }
    return NO_ERROR;
}
示例#10
0
 static inline bool WriteExactly(int fd, const void* buf, size_t count) {
   return WriteFully(fd, buf, count) == count;
 }
NS_IMETHODIMP
nsBinaryOutputStream::Write32(PRUint32 a32)
{
    a32 = NS_SWAP32(a32);
    return WriteFully((const char*)&a32, sizeof a32);
}
NS_IMETHODIMP
nsBinaryOutputStream::Write16(PRUint16 a16)
{
    a16 = NS_SWAP16(a16);
    return WriteFully((const char*)&a16, sizeof a16);
}
NS_IMETHODIMP
nsBinaryOutputStream::Write8(PRUint8 aByte)
{
    return WriteFully((const char*)&aByte, sizeof aByte);
}
示例#14
0
NS_IMETHODIMP
nsBinaryOutputStream::Write32(uint32_t a32)
{
    a32 = mozilla::NativeEndian::swapToBigEndian(a32);
    return WriteFully((const char*)&a32, sizeof a32);
}
示例#15
0
NS_IMETHODIMP
nsBinaryOutputStream::Write16(uint16_t a16)
{
    a16 = mozilla::NativeEndian::swapToBigEndian(a16);
    return WriteFully((const char*)&a16, sizeof a16);
}