我有一个应用程序,我移植到Microsoft Visual Studio 2008,在Linux上构建和运行良好.
我遇到时间例程的麻烦,我的Linux代码看起来像这样:
#include <sys/types.h>
#include <sys/time.h>
typedef long long Usec;
inline Usec timevalToUsec(const timeval &tv)
{
return (((Usec) tv.tv_sec) * 1000000) + ((Usec) tv.tv_usec);
}
Run Code Online (Sandbox Code Playgroud)
但编译器在sys/time.h头文件上失败:
fatal error C1083: Cannot open include file:
'sys/time.h': No such file or directory
Run Code Online (Sandbox Code Playgroud)
如果我将include更改为只是time.h我得到一个不同的错误timeval未定义:
error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
Run Code Online (Sandbox Code Playgroud)
这是由于timeval没有定义.
包含time.h而不是sys/time.h正确,如果是,我在哪里可以获得struct timevalMicrosoft Visual Studio 2008中的定义?
在我的 C++ 应用程序中,我将 ::bind() 用于 UDP 套接字,但在极少数情况下,由于连接丢失而重新连接后,即使经过多次重试,我也会收到 errno EADDRINUSE。UDP 连接的另一端将接收重新连接好的数据并等待 select() 指示有内容要读取。
我认为这意味着本地端口正在使用中。如果为真,我怎么可能会泄漏本地端口,以便另一端可以正常连接到它?这里真正的问题是另一侧连接正常并且正在等待,但这一侧卡在 EADDRINUSE 上。
- 编辑 -
这是一个代码片段,显示我已经在我的 TCP 套接字上执行 SO_REUSEADDR,而不是在我遇到问题的这个 UDP 套接字上:
// According to "Linux Socket Programming by Example" p. 319, we must call
// setsockopt w/ SO_REUSEADDR option BEFORE calling bind.
// Make the address is reuseable so we don't get the nasty message.
int so_reuseaddr = 1; // Enabled.
int reuseAddrResult
= ::setsockopt(getTCPSocket(), SOL_SOCKET, SO_REUSEADDR, &so_reuseaddr,
sizeof(so_reuseaddr));
Run Code Online (Sandbox Code Playgroud)
这是我在完成后关闭 UDP 套接字的代码:
void
disconnectUDP()
{
if (::shutdown(getUDPSocket(), …Run Code Online (Sandbox Code Playgroud) 我有一个 makefile,当使用旧版本的 gmake 时,它会出现不明显的故障。我想有一个规则来检查版本至少是 3.82 或更高版本。我已经得到了以下规则,但比较是脆弱的,我真的想要一个允许更高版本的比较:
GMAKE_VERSION := $(shell gmake --version | head -n 1 | sed 's/GNU Make //')
.PHONY: testMake
testMake:
@if [ "$(GMAKE_VERSION)" != "3.82" ]; \
then \
echo >&2 "Unexpected gmakefile version " \
"$(GMAKE_VERSION), expecting 3.82 or later."; \
false; \
fi
Run Code Online (Sandbox Code Playgroud)
什么GNU makefile规则可以保证make的版本至少是v3.82?
基于一些实验,在我看来,以下Python v2.7代码:
def lookup_pattern(pattern, file_containing_patterns):
for line in file_containing_patterns:
splits = line.split()
if splits:
if (pattern == splits[0]):
return map(lambda x: x.strip(), splits[1:])
return None
Run Code Online (Sandbox Code Playgroud)
可以简化如下砸map的strip():
def lookup_pattern(pattern, file_containing_patterns):
for line in file_containing_patterns:
splits = line.split()
if splits:
if (pattern == splits[0]):
return splits[1:]
return None
Run Code Online (Sandbox Code Playgroud)
我相信这是真的,因为split()应该删除所有的空白区域,因此这strip()将是一个无操作.
是否有任何情况下,上述两个效果不相同,如果是,它们是什么?
我希望在命令中有一个注释,看起来这是不可能的,因为在Tcl 8.4中定义的'#'字符是:
如果散列字符("#")出现在Tcl期望命令的第一个单词的第一个字符的位置,那么散列字符及其后面的字符,直到下一个换行符,被视为评论并被忽略.注释字符仅在命令开头出现时才有意义.
想象一下这个如何工作的例子(这些评论在我的实验中都没有奏效):
array set myArray [list red 3 \
blue 4 ;# Blue is before purple.
purple 5 # Purple is after red.
green 7 \
yellow 8]
Run Code Online (Sandbox Code Playgroud)
似乎棘手的部分是如何在嵌入注释的情况下继续列表命令?也许类似C++风格的/*Embedded评论.*/但我只看到#在Tcl中用于注释到行尾,没有用于开始和结束注释语法.
我有一个服务器应用程序,可以使用inetd为客户端召唤.但是,如果我尝试连接到使用inetd启动的服务器进程,我会得到以下响应:ptrace:不允许操作.
gdb --annotate=3 /my/app/here <processId>
Current directory is /usr/local/bin/
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
Reading symbols from /usr/local/bin/flumed...done.
Using host libthread_db library "/lib/tls/libthread_db.so.1".
Attaching to program: /my/app/here, process <processId>
ptrace: …Run Code Online (Sandbox Code Playgroud) 如果我使用块密码为128位的块密码,如果我的数据不是128位的偶数倍,我该怎么办?我正在处理数据包,并且在加密数据时不想更改数据包的大小,但我的数据不是128的偶数倍?
AES分组密码是否允许处理最后一个短的块,而不会在加密后更改消息的大小?
我有一个像这样的头文件:
/*
* APP 180-2 ALG-254/258/772 implementation
* Last update: 03/01/2006
* Issue date: 08/22/2004
*
* Copyright (C) 2006 Somebody's Name here
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must …Run Code Online (Sandbox Code Playgroud) 是否应该将Unix GUI应用程序的警告发送到std :: cerr或std :: cout?
这假定GUI通常在控制台窗口中显示警告和错误,并将它们发送到日志文件.但是如果控制台丢失并因此无法使用std :: cerr,std :: cout或std :: clog用于此类消息?
我在想std :: cerr是他们所属的地方.
我有一个C++应用程序,有一次断言失败,我无法重现.这是失败一次的代码:
unsigned int test(std::vector<CAction> actionQueue) {
unsigned int theLastCount = actionQueue.size() - 1;
std::vector<CAction>::const_reverse_iterator rItr = actionQueue.rbegin();
std::vector<CAction>::const_reverse_iterator rEndItr = actionQueue.rend();
for (; rItr != rEndItr; ++rItr, --theLastCount) {
const CAction &fileAction = *rItr;
if (fileAction.test()) {
continue;
}
return theLastCount;
}
assert(theLastCount == 0); // How could this fail?
return theLastCount;
}
Run Code Online (Sandbox Code Playgroud)
不知何故,循环完成后,LastCount不为零.
从我对逻辑的解读,这应该是不可能的,除非:
我在这里错过了一些愚蠢的东西,我的代码中是否有错误显示?请注意,在我看到这个的情况下,由于向量具有两个元素,因此应该将LastCount初始化为1.