1

libwebsockets を使用して、ブラウザとサービスを接続するための小さなサービスを開発しています。httpで動作する場合、すべて問題ありません。しかし、openssl で https に切り替えると、うまく動作しません。たとえば、ブラウザでハイパーリンクをクリックすると、サービスは画像を返す必要があります。しかし、動作が非常に遅いです。このアクションを実行すると、私のCPUは約50%実行されます。私はただ混乱していて、あなたの助けが必要です。本当に感謝します〜メインコードは以下のようにリストされています:

case LWS_CALLBACK_HTTP:

    /* check for the "send a big file by hand" example case */
    sprintf(cache_file, "%s\\%s", g_cache_path, (char*)in+1);
    n = GetLastIndex(cache_file, '/');
    if (n >= 0)
    {
        cache_file[n] = '\\';
    }
    p = buffer;

            // cache_file is my file name , should be transfer
    pss->hFile = CreateFile(cache_file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);

    if (pss->hFile == NULL || pss->hFile == INVALID_HANDLE_VALUE)
        return -1;

    //fstat(pss->hFile, &stat_buf);

    /*
     * we will send a big jpeg file, but it could be
     * anything.  Set the Content-Type: appropriately
     * so the browser knows what to do with it.
     */

    p += sprintf((char *)p,
        "HTTP/1.0 200 OK\x0d\x0a"
        "Server: libwebsockets\x0d\x0a"
        "Content-Type: image/png\x0d\x0a"
            "Content-Length: %u\x0d\x0a\x0d\x0a",
            GetFileSize(pss->hFile, 0));

    /*
     * send the http headers...
     * this won't block since it's the first payload sent
     * on the connection since it was established
     * (too small for partial)
     */

    n = libwebsocket_write(wsi, buffer,
           p - buffer, LWS_WRITE_HTTP);

    if (n < 0) {
        CloseHandle(pss->hFile);
        return -1;
    }
    /*
     * book us a LWS_CALLBACK_HTTP_WRITEABLE callback
     */
    libwebsocket_callback_on_writable(context, wsi);
    break;

case LWS_CALLBACK_HTTP_WRITEABLE:

    do {
        ReadFile(pss->hFile, buffer, sizeof buffer, &readLen, NULL);

        if (readLen <= 0)
            goto bail;

        m = libwebsocket_write(wsi, buffer, readLen, LWS_WRITE_HTTP);
        if (m < 0)
            /* write failed, close conn */
            goto bail;
        if (m != readLen)
            /* partial write, adjust */
            SetFilePointer(pss->hFile, m - readLen, 0, FILE_CURRENT);

    } while (!lws_send_pipe_choked(wsi));
    libwebsocket_callback_on_writable(context, wsi);
    break;
4

0 に答える 0