我以为我已经想到了这一切,但现在我正在写一个网络服务器,有些东西不太正常.
应用程序在端口上侦听传入的请求,当收到请求时,它会读取所有内容,直到序列"\ r \n \n \n \n".(因为这表示标题的结尾 - 是的,我忽略了可能的POST数据.)
现在,在读取了那么远之后,它会向套接字写入响应:
HTTP/1.1 200 OK\r\n
Host: 127.0.0.1\r\n
Content-type: text/html\r\n
Content-length: 6\r\n
\r\n
Hello!
Run Code Online (Sandbox Code Playgroud)
但是,当Firefox或Chrome尝试查看该页面时,它将不会显示.Chrome通知我:
错误324(net :: ERR_EMPTY_RESPONSE):未知错误.
我究竟做错了什么?
以下是一些代码:
QTcpSocket * pSocket = m_server->nextPendingConnection();
// Loop thru the request until \r\n\r\n is found
while(pSocket->waitForReadyRead())
{
QByteArray data = pSocket->readAll();
if(data.contains("\r\n\r\n"))
break;
}
pSocket->write("HTTP/1.0 200 OK\r\n");
QString error_str = "Hello world!";
pSocket->write("Host: localhost:8081\r\n");
pSocket->write("Content-Type: text/html\r\n");
pSocket->write(tr("Content-Length: %1\r\n").arg(error_str.length()).toUtf8());
pSocket->write("\r\n");
pSocket->write(error_str.toUtf8());
delete pSocket;
Run Code Online (Sandbox Code Playgroud) 好的,所以我使用的是mingW,直接结构没有名为d_type或stat,d_stat或dd_stat的变量.我需要知道如何使用我的直接结构来确定我所拥有的是文件或文件夹.这是我的代码.
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
/*function... might want it in some class?*/
int getdir (string dir, vector<string> &files)
{
DIR *dp;
struct stat _buf;
struct dirent *dirp;
if((dp = opendir(dir.c_str())) == NULL) {
cout << "Error(" << errno << ") opening " << dir << endl;
return errno;
}
while ((dirp = readdir(dp)) != NULL) {
if(stat(dirp->d_name, &_buf) != 0x4)
files.push_back(string(dirp->d_name));
}
closedir(dp);
return 0;
}
int …Run Code Online (Sandbox Code Playgroud) 我有一个外部的js文件处理删除一些元素.根据结果,我将确定是否需要刷新页面.
var deleted = 0; // first assume not deleted
$(function() {
$("#action a.action-delete").click(function() {
var id = $(this).parent().parent().attr("id");
$.get("modify-sale.php", { "id" : id, "action" : "delete" }, function (data) { deleted = 1; }, "text");
if (deleted) return true; // if success then refresh
else return false; // else does not refresh
});
Run Code Online (Sandbox Code Playgroud)
没问题是我无法deleted在jQuery事件处理程序中更改全局变量.我可以确保删除操作成功,但此变量不会将其值更改为1.
为什么?
我按下按钮时试图让UIView摇晃.
我正在调整我在http://www.cimgf.com/2008/02/27/core-animation-tutorial-window-shake-effect/上找到的代码.
但是,通过尝试调整以下代码来动摇UIView,它不起作用:
- (void)animate {
const int numberOfShakes = 8;
const float durationOfShake = 0.5f;
const float vigourOfShake = 0.1f;
CAKeyframeAnimation *shakeAnimation = [CAKeyframeAnimation animation];
CGRect frame = lockView.frame;
CGMutablePathRef shakePath = CGPathCreateMutable();
CGPathMoveToPoint(shakePath, NULL, CGRectGetMinX(frame), CGRectGetMinY(frame));
for (int index = 0; index < numberOfShakes; ++index) {
CGPathAddLineToPoint(shakePath, NULL, CGRectGetMinX(frame) - frame.size.width * vigourOfShake, CGRectGetMinY(frame));
CGPathAddLineToPoint(shakePath, NULL, CGRectGetMinX(frame) + frame.size.width * vigourOfShake, CGRectGetMinY(frame));
}
CGPathCloseSubpath(shakePath);
shakeAnimation.path = shakePath;
shakeAnimation.duration = durationOfShake;
[lockView.layer addAnimation:shakeAnimation forKey:@"frameOrigin"];
}
Run Code Online (Sandbox Code Playgroud) 这是我的功能:
void abc(char *def, unsigned int w, unsigned int x, unsigned int y, unsigned int z)
{
printf("val 1 : %d\n", w);
printf("val 2 : %d\n", x);
printf("val 3 : %d\n", y);
printf("val 4 : %d\n", z);
}
Run Code Online (Sandbox Code Playgroud)
这是我调用此函数的地方:
unsigned int exp[4] = { 1, 2, 3, 4 };
unsigned short count = 0;
abc(anyarray, exp[count++], exp[count++], exp[count++], exp[count++]);
Run Code Online (Sandbox Code Playgroud)
这是我期望的输出:
val1 : 1
val2 : 2
val3 : 3
val4 : 4
Run Code Online (Sandbox Code Playgroud)
但我得到的完全相反:
val1 : 4
val2 : 3
val3 …Run Code Online (Sandbox Code Playgroud) 我正在使用vanilla ga异步代码,就在结束之前</head>:
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxx-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
Run Code Online (Sandbox Code Playgroud)
现在,稍后在页面中间我打电话:
<script>
_gaq.push(['_setCustomVar',
1,
'usertype',
'anon',
2
]);
</script>
Run Code Online (Sandbox Code Playgroud)
问题是,我是否需要再次调用_trackPageView?
也就是说,我应该添加另一个
_gaq.push(['_trackPageview']);
...?
如何制作Java打印"Hello"?
当我键入System.out.print("Hello");输出时Hello.我正在寻找的是"Hello"引号("").
我有一个数字列表,例如21,4,7,9,12,22,17,8,2,20,23
我希望能够选出序列号序列(最少3个项目),所以从上面的例子可以看出它是7,8,9和20,21,22,23.
我玩了一些丑陋的庞大功能,但我想知道是否有一个简洁的LINQ-ish方法来做到这一点.
有什么建议?
更新:
非常感谢所有的回应,非常感谢.我现在正和他们一起玩,看看哪个最适合我们的项目.
我有一个接受2 N位数的程序,使用线程将它们相乘并打印输出.
这里创建的线程数是2 * N - 1.
每当我运行程序时N > 151,程序都会给我一个分段错误.
进程可以从线程池获得的最大线程数是否有上限?
如果是这样,这可能是错误的正当理由吗?
编辑:
Valgrind发现没有内存泄漏N <= 150.
我在Linux 2.6.x内核中运行该程序.