我期待输出2,3,但我得到了垃圾值.为什么?
这是我的代码:
#include <iostream>
using namespace std;
class A
{
public:
int a, b;
A()
{
cout << a << " " << b;
}
A(int x, int y)
{
a = x;
b = y;
A(); // calling the default constructor
}
};
int main()
{
A ob(2, 3);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 当BIO是内存BIO而不是套接字BIO时,我对BIO例程BIO_read()/ BIO_write()和SSL_read()/ SSL_write()之间的区别感到困惑.
我正在尝试使用libnice为ICE堆栈编写WebRTC服务器,并为DTLS堆栈编写openssl.ICE堆栈具有到客户端的套接字连接,因此我无法在openssl中使用基于套接字的BIO.相反,我正在使用内存BIO.
所以我使用的高级过程是,当我从ICE套接字上的客户端收到DTLS消息时,我使用BIO_write()将该消息写入DTLS堆栈.然后,当DTLS堆栈有一条要发送到客户端的消息时,我使用BIO_read()获取该消息,并使用ICE套接字将其发送到客户端.
我已经看到了一些基本上执行此过程的源代码示例,但是在BIO_write()调用之后它们也调用了SSL_read()例程.这对我来说毫无意义.在我基本上使用BIO_write()调用将客户端消息写入DTLS堆栈之后,为什么需要调用SSL_read()?如果我在BIO_write()之后没有调用SSL_read(),那么我的代码不起作用.但是当我在BIO_write()之后调用SSL_read()时,这确实是与浏览器客户端交换握手消息.
问题:使用内存BIO,BIO_read()和SSL_read()之间有什么区别; 问题:使用内存BIO,BIO_write()和SSL_write()之间有什么区别?问题:默认内存是BIO阻塞还是非阻塞?我假设它是非阻塞的,因为它是基于内存的BIO而不是基于套接字的BIO.
谢谢,-Andres
我是 Valgrind 的新手。在对以下代码 ( http://en.cppreference.com/w/cpp/thread/lock_guard )进行内存检查期间,它会引发 2 个错误。不知道如何解释这些错误。
#include <thread>
#include <mutex>
#include <iostream>
int g_i = 0;
std::mutex g_i_mutex; // protects g_i
void safe_increment()
{
std::lock_guard<std::mutex> lock(g_i_mutex);
++g_i;
std::cout << std::this_thread::get_id() << ": " << g_i << '\n';
}
int main()
{
std::cout << __func__ << ": " << g_i << '\n';
std::thread t1(safe_increment);
std::thread t2(safe_increment);
t1.join();
t2.join();
std::cout << __func__ << ": " << g_i << '\n';
}
Run Code Online (Sandbox Code Playgroud)
我使用以下命令在 Mac 上编译了这段代码:
clang++ simplethread.cpp -o simplethread -lpthread -std=c++11
Run Code Online (Sandbox Code Playgroud)
代码按预期运行,但我从 …
我正在尝试连接到远程主机以发出命令,但在运行代码时收到以下错误消息:
\n\n\n\n\nssh:握手失败:ssh:没有通用的密钥交换算法;客户端提供:[curve25519-sha256@libssh.org ecdh-sha2-nistp256 ecdh-sha2-nistp384 ecdh-sha2-nistp521 diffie-hellman-group14-sha1],服务器提供:[diffie-hellman-group1-sha1]恐慌:运行时错误:无效的内存地址或零指针取消引用\n [信号 SIGSEGV:分段违规代码 = 0x1 addr = 0x10 pc = 0x759836]
\n
这是我正在使用的代码:
\n\nfunc\xc2\xa0(SSHClient\xc2\xa0*SSH)\xc2\xa0Connect(mode\xc2\xa0int)\xc2\xa0{\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0var\xc2\xa0SSHConfig\xc2\xa0*ssh.ClientConfig\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0var\xc2\xa0auth\xc2\xa0[]ssh.AuthMethod\n\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0if\xc2\xa0mode\xc2\xa0==\xc2\xa0CERT_PUBLIC_KEY_FILE\xc2\xa0{\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0auth\xc2\xa0=\xc2\xa0[]ssh.AuthMethod{SSHClient.readPublicKeyFile(SSHClient.Cert)}\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0}\n\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0SSHConfig\xc2\xa0=\xc2\xa0&ssh.ClientConfig{\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0User:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0SSHClient.User,\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0Auth:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0auth,\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0HostKeyCallback:\xc2\xa0ssh.InsecureIgnoreHostKey(),\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0Timeout:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0time.Second\xc2\xa0*\xc2\xa0DEFAULT_TIMEOUT,\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0}\n\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0SSHConfig.Config.Ciphers\xc2\xa0=\xc2\xa0append(SSHConfig.Config.Ciphers,\xc2\xa0"diffie-hellman-group1-sha1")\n\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0client,\xc2\xa0err\xc2\xa0:=\xc2\xa0ssh.Dial("tcp",\xc2\xa0fmt.Sprintf("%s:%d",\xc2\xa0SSHClient.IP,\xc2\xa0SSHClient.Port),\xc2\xa0SSHConfig)\n\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0if\xc2\xa0err\xc2\xa0!=\xc2\xa0nil\xc2\xa0{\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0fmt.Printf("ERROR\xc2\xa0-\xc2\xa0While\xc2\xa0trying\xc2\xa0to\xc2\xa0Dial\xc2\xa0to\xc2\xa0the\xc2\xa0host\xc2\xa0%s\xc2\xa0with\xc2\xa0error:\xc2\xa0%s",\xc2\xa0SSHClient.IP,\xc2\xa0err.Error())\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0return\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0}\n\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0session,\xc2\xa0err\xc2\xa0:=\xc2\xa0client.NewSession()\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0if\xc2\xa0err\xc2\xa0!=\xc2\xa0nil\xc2\xa0{\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0fmt.Printf("ERROR\xc2\xa0-\xc2\xa0While\xc2\xa0trying\xc2\xa0to\xc2\xa0create\xc2\xa0a\xc2\xa0new\xc2\xa0session\xc2\xa0on\xc2\xa0host\xc2\xa0%s\xc2\xa0with\xc2\xa0error:\xc2\xa0%s",\xc2\xa0SSHClient.IP,\xc2\xa0err.Error())\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0client.Close()\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0return\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0}\n\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0SSHClient.session\xc2\xa0=\xc2\xa0session\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0SSHClient.client\xc2\xa0=\xc2\xa0client\n}\nRun Code Online (Sandbox Code Playgroud)\n\n关于如何解决这个问题有什么想法吗?
\n\n提前致谢。
\n我正在为市场开发 GitHub Action。它有各种带有默认值的输入。这些输入之一恰好是boolean我用来切换调试状态的输入。
这是我的布尔输入定义:
inputs:
debug_mode:
description: "Controls the debug mode, boolean, true is for on. When turned on, it'll output certain information on certain steps. Mainly used for development, but use it as you please to inspect your env and variables."
type: boolean
required: false
default: false
Run Code Online (Sandbox Code Playgroud)
boolean正如您所看到的,它具有带默认值的类型false。然后,在其中一个步骤中,我检查debug_mode以确定是否运行该步骤。但是,它没有按预期工作:
steps:
- name: Dump debug_mode
run: echo "debug_mode is ${{ inputs.debug_mode }}"
shell: bash
- name: Dump context
if: ${{ inputs.debug_mode}}
uses: crazy-max/ghaction-dump-context@v2
- …Run Code Online (Sandbox Code Playgroud) 我试图声明一个动态int数组,如下所示:
int n;
int *pInt = new int[n];
Run Code Online (Sandbox Code Playgroud)
我可以这样做std::auto_ptr吗?
我尝试过类似的东西:
std::auto_ptr<int> pInt(new int[n]);
Run Code Online (Sandbox Code Playgroud)
但它没有编译.
我想知道我是否可以使用auto_ptr构造和如何声明动态数组.谢谢!
我被jsoncpp困住了。我想创建一个像这样的数组:
"Cords": [{"x": 10, "y": 20}, {"x": 70, "y": 40}, {"x": 15, "y": 65}]
Run Code Online (Sandbox Code Playgroud)
我设法用 jsoncpp 做常规的事情(见下文),但我陷入了制作 JSON 数组的情况。
Json::Value event;
event["name"] = "Joe";
event["Direction"]["left"]["x"] = "1338";
event["Direction"]["right"]["x"] = "1337";
Run Code Online (Sandbox Code Playgroud)
编辑:
我想在事件中打印所有内容。
我不想单独打印电线。
下面是R使用双指针填充struct数组的示例代码.我无法分配内存r[0],并且还当函数退出,都r和r[0]变0x0.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct R
{
int x;
int y;
char * z;
};
void func(struct R **r)
{
r = (struct R **) malloc(4 * sizeof(struct R *));
r[0] = (struct R *) malloc(sizeof(struct R)); // giving r[0] = 0x0
r[0]->x = 1;
r[0]->y = 2;
r[0]->z = (char *) malloc(64 * sizeof(char));
strcpy(r[0]->z , "HELLO");
}
int main()
{
struct R *r = NULL; …Run Code Online (Sandbox Code Playgroud) 我的C++代码中有一些带有绑定的SQL查询,这些查询是static const std::string,因为这些查询很复杂,所以很容易出错.我想在编译时做一些非常基本的检查,例如计算逗号或:字符的数量.
我目前正在尝试为CKEditor 5编写一个插件来支持自动翻译。我能够在文档中找到如何编写插件以及如何创建下拉菜单。
但在文档中没有提及(或者我错过了)如何获知有关单击值的信息:
id或类似的符号来识别下拉列表右侧元素的点击吗?这是我根据文档构建的代码:
class Translation extends Plugin {
init() {
this.editor.ui.componentFactory.add('translate', (locale) => {
const dropdownView = createDropdown(locale);
dropdownView.buttonView.set({
icon: languageIcon,
label: 'Translate',
tooltip: true,
});
const items = new Collection();
items.add({
id: 'en', // how to assign id ???
type: 'button',
model: new Model({
withText: true,
label: 'English'
}),
});
items.add({
id: 'es', // how to assign id ???
type: 'button',
model: new Model({
withText: true,
label: 'Spanish'
}),
});
addListToDropdown(dropdownView, …Run Code Online (Sandbox Code Playgroud)