如果文件是常规文件(并且不是目录,管道等),我如何签入C++?我需要一个函数isFile().
DIR *dp;
struct dirent *dirp;
while ((dirp = readdir(dp)) != NULL) {
if ( isFile(dirp)) {
cout << "IS A FILE!" << endl;
i++;
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试将dirp-> d_type与(unsigned char)0x8进行比较,但它似乎无法通过不同的系统进行移植.
使用类似http://example.com的URL调用函数CheckSite(),它初始化QNetworkAccessManager对象和connect()槽和信号.
manger-> get()调用似乎有效(它生成http流量),但在请求结束时不调用插槽replyFinished().
这段代码出了什么问题?
#include <QtCore>
#include <QtNetwork>
class ClientHandler : public QObject
{
Q_OBJECT
QNetworkAccessManager *manager;
private slots:
void replyFinished(QNetworkReply *);
public:
void CheckSite(QString url);
};
void ClientHandler::replyFinished(QNetworkReply *reply) { qDebug() << "DONE"; }
void ClientHandler::CheckSite(QString url) {
QUrl qrl(url);
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(qrl));
}
Run Code Online (Sandbox Code Playgroud) 为什么我有这个简单的代码
void voidFunct() {
printf("voidFunct called!!!\n");
}
Run Code Online (Sandbox Code Playgroud)
我将其编译为动态库
gcc -c LSB.c -o LSB.o
gcc -shared -Wl -o libLSB.so.1 LSB.o
Run Code Online (Sandbox Code Playgroud)
我使用ctypes从python解释器调用函数
>>> from ctypes import *
>>> dll = CDLL("./libLSB.so.1")
>>> return = dll.voidFunct()
voidFunct called!!!
>>> print return
17
Run Code Online (Sandbox Code Playgroud)
为什么从void
方法返回的值是17
和不None
相似?谢谢.
正如标题所说,Python cStringIO是否保护其内部结构以供多线程使用?
谢谢.
我在使用带有AF_UNIX套接字的asyncore时遇到了一些问题.这段代码
import asyncore, socket, os
class testselect(asyncore.dispatcher):
path = '/tmp/mysocket'
def __init__(self):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_UNIX, socket.SOCK_DGRAM)
self.bind(self.path)
self.buffer = 'buffer'
def handle_connect(self):
print 'handle_connect'
pass
def handle_close(self):
print 'handle_close'
if os.path.exists(self.path)
os.remove(self.path)
self.close()
def handle_read(self):
print 'handle_read'
print self.recv(8192)
def writable(self):
print 'writable'
return (len(self.buffer) > 0)
def handle_write(self):
print 'handle_write'
sent = self.send(self.buffer)
self.buffer = self.buffer[sent:]
client = testselect()
asyncore.loop()
Run Code Online (Sandbox Code Playgroud)
如果我执行代码
$ python select_prova.py
writable
handle_connect
handle_write
handle_close
$
Run Code Online (Sandbox Code Playgroud)
它立即退出,不等待读写.如果我改变代码以强制writable()方法总是返回False
,它正确地等待输入,我可以像这样与socat通信
$ socat readline UNIX:/tmp/mysocket
Run Code Online (Sandbox Code Playgroud)
但只是为了阅读(逻辑上写不起作用,因为writable()返回False
).我的代码中是否有错误,或者我无法使用asyncore/select()管理AF_UNIX套接字?
有一个简单的C++方法在字符串上使用模式匹配?代码听起来像这样:
if (regexpcmp("l?nole*[0-9]", "linoleum1")) {
//we have a match!
} else {
//no match
}
Run Code Online (Sandbox Code Playgroud) 编译这一行
long int sz;
char tmpret[128];
//take substring of c, translate in c string, convert to int,
//and multiply with 1024
sz=atoi(c.substr(0,pos).c_str())*1024;
snprintf(tmpret,128,"%l",sz);
Run Code Online (Sandbox Code Playgroud)
我在snprintf上读了两个警告:
warning: conversion lacks type at end of format
warning: too many arguments for format
Run Code Online (Sandbox Code Playgroud)
为什么?指定了类型(long int sz和snprintf中的%l),snprintf中的参数只有一个.有谁能够帮我?谢谢.
我必须计算RTP流中的数据包之间的时间偏移.使用Theora编解码器编码的视频流我有时间戳字段
2856000
2940000
3024000
...
Run Code Online (Sandbox Code Playgroud)
所以我假设传输偏移是84000.使用音频speex编解码器我有时间戳字段
38080
38400
38720
...
Run Code Online (Sandbox Code Playgroud)
所以我假设传输偏移是320.为什么值如此不同?它们是微秒,毫秒还是什么?我可以推广一个公式来计算与任何编解码器一起使用的数据包之间的延迟(以微秒为单位)吗?谢谢.
Scapy中的TCP层包含源端口:
>>> a[TCP].sport
80
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法将端口号转换为服务名称?我见过Scapy TCP_SERVICES
并且UDP_SERVICES
要翻译端口号,但是
print TCP_SERVICES[80] # fails
print TCP_SERVICES['80'] # fails
print TCP_SERVICES.__getitem__(80) # fails
print TCP_SERVICES['www'] # works, but it's not what i need
80
Run Code Online (Sandbox Code Playgroud)
有人知道如何将端口映射到服务?
先感谢您
我必须编写一个轻量级算法来生成伪随机无限数字序列,并且强烈依赖于初始种子.
在python中应该是这样的
seed = 3345 // Common number
generator = numgen(seed)
while True:
generator.getNext() // With the same seed it produce same numbers
Run Code Online (Sandbox Code Playgroud)
正如我所写的,使用相同的种子,它必须生成相同的数字系列,即使在不同的机器和不同的时间.是否有标准模式或我是否必须实现自己的算法?
python ×5
c++ ×3
algorithm ×1
asyncore ×1
c ×1
ctypes ×1
dirent.h ×1
filesystems ×1
format ×1
generator ×1
numbers ×1
offset ×1
printf ×1
qt ×1
qt4 ×1
regex ×1
return-value ×1
rtp ×1
scapy ×1
series ×1
signals ×1
slot ×1
sockets ×1
string ×1
stringio ×1
tcp ×1
timestamp ×1
types ×1
unix-socket ×1
voip ×1