小编Dr.*_*all的帖子

有没有办法在套接字通道上取消注册选择器

这是一个非常直截了当的问题,但我发现需要取消注册选择器,忽略我的套接字通道的java.

SocketChannel client = myServer.accept(); //forks off another client socket
client.configureBlocking(false);//this channel takes in multiple request
client.register(mySelector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);//changed from r to rw
Run Code Online (Sandbox Code Playgroud)

我可以在以后的程序中调用类似的东西

client.deregister(mySelector);
Run Code Online (Sandbox Code Playgroud)

并且选择器将不再捕获该套接字通道的数据键.鉴于我的服务器/客户端设计,这将使我的生活更轻松.

java sockets select nonblocking socketchannel

8
推荐指数
2
解决办法
7448
查看次数

如何使用apache HttpClient传递响应体

有一个api我需要执行没有长度的八位字节流.它只是一个实时数据流.我遇到的问题是,当我提出请求时,它似乎试图在将信息读入输入流之前等待内容的结束,但是它没有看到内容的结束和具有NoHttpResponse异常的超时.以下是我的代码的简化版本:

private static HttpPost getPostRequest() {
    // Build uri
    URI uri = new URIBuilder()
            .setScheme("https")
            .setHost(entity.getStreamUrl())
            .setPath("/")
            .build();

    // Create http http
    HttpPost httpPost = new HttpPost(uri);

    String nvpsStr = "";
    Object myArray[] = nvps.toArray();
    for(int i = 0; i < myArray.length; i ++) {
        nvpsStr += myArray[i].toString();
        if(i < myArray.length - 1) {
            nvpsStr += "&";
        }
    }

    // Build http payload
    String request = nvpsStr + scv + streamRequest + "\n\n";
    // Attach http data
    httpPost.setEntity(new StringEntity(URLEncoder.encode(request,"UTF-8")));

    return …
Run Code Online (Sandbox Code Playgroud)

java httpclient apache-commons-httpclient apache-httpclient-4.x

8
推荐指数
1
解决办法
2万
查看次数

你如何处理Akka Flow的期货?

我已经构建了一个定义流的akka​​图.我的目标是重新格式化我将来的响应并将其保存到文件中.流程可以概述如下:

val g = RunnableGraph.fromGraph(GraphDSL.create() { implicit builder: GraphDSL.Builder[NotUsed] =>
      import GraphDSL.Implicits._
      val balancer = builder.add(Balance[(HttpRequest, String)](6, waitForAllDownstreams = false))
      val merger = builder.add(Merge[Future[Map[String, String]]](6))
      val fileSink = FileIO.toPath(outputPath, options)
      val ignoreSink = Sink.ignore
      val in = Source(seeds)
      in ~> balancer.in
      for (i <- Range(0,6)) {
        balancer.out(i) ~>
          wikiFlow.async ~>
          // This maps to a Future[Map[String, String]]
          Flow[(Try[HttpResponse], String)].map(parseHtml) ~>
          merger
      }

      merger.out ~>
      // When we merge we need to map our Map to a file
      Flow[Future[Map[String, String]]].map((d) => …
Run Code Online (Sandbox Code Playgroud)

scala future akka akka-stream

8
推荐指数
1
解决办法
4462
查看次数

找到pcap.h和链接的问题

我正在使用Fedora 17,我想用libpcap编程.问题是我的计算机没有找到pcap.h,因为我安装了libpcap和libpcap-devel,这真的很奇怪.还有wireshark和snort在我的工作站工作,我相信使用该库.所以当我用...编译我的代码时

#include <pcap.h>
... Code
Run Code Online (Sandbox Code Playgroud)

并使用gcc my_file.c -lpcap,我得到编译器错误,说...找不到pcap.h. 奇怪的是,我在/ libraries /目录中看到了我的libpcap.so文件.我弄完了 ..

yum install libpcap和yum install libpcap-devel

我不知道为什么Fedora会对我这样做.

谢谢你的帮助!

c linux fedora libpcap

7
推荐指数
3
解决办法
4万
查看次数

Autoloader预期类Symfony2

我正在使用symfony 2.3框架,自动加载器声称已找到该文件,但没有类:

RuntimeException: The autoloader expected class "Sensio\Bundle\
FrameworkExtraBundle\Request\ParamConverter\DateTimeParamConverter" 
to be defined in file "/home/na/auth/vendor/sensio/framework-extra-bundle/
Sensio/Bundle/FrameworkExtraBundle/Request/ParamConverter/
DateTimeParamConverter.php". The file was found but the class was not in it, 
the class name or namespace probably has a typo.
Run Code Online (Sandbox Code Playgroud)

这个引用的文件如下所示:

<?php

/*
 * This file is part of the Symfony framework.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace …
Run Code Online (Sandbox Code Playgroud)

php autoloader symfony doctrine-orm

7
推荐指数
3
解决办法
1万
查看次数

Bash"declare -A"不适用于macOS

我猜是Bash没有在macOS上更新.当谷歌搜索更新Bash macOS时,我不断收到错误修复补丁.无论如何,我需要在macOS Bash中使用关联数组,其中命令:

declare -A
Run Code Online (Sandbox Code Playgroud)

产生错误:

-bash:declare:-A:invalid option
declare:usage:declare [-afFirtx] [-p] [name [= value] ...]

我有优胜美地.

linux macos bash associative-array

7
推荐指数
1
解决办法
2616
查看次数

我如何等待 ThreadPoolExecutor.map 完成

我有以下已简化的代码:

import concurrent.futures

pool = concurrent.futures.ThreadPoolExecutor(8)

def _exec(x):
    return x + x

myfuturelist = pool.map(_exec,[x for x in range(5)])

# How do I wait for my futures to finish?

for result in myfuturelist:
    # Is this how it's done?
    print(result)

#... stuff that should happen only after myfuturelist is
#completely resolved.
# Documentation says pool.map is asynchronous
Run Code Online (Sandbox Code Playgroud)

关于 ThreadPoolExecutor.map 的文档很薄弱。帮助会很棒。

谢谢!

python python-multithreading python-3.x

7
推荐指数
3
解决办法
1万
查看次数

如何使用gdb读取所有寄存器的值?

我在汇编中调试ac程序,以了解gcc编译器的工作原理.我想读取我的$ fs段寄存器,所以我使用x/x $ fs,但它告诉我它无法访问内存.如何读取i386上包含段,通用和控制寄存器的任何寄存器:86_64?

assembly gcc gdb cpu-registers linux-kernel

6
推荐指数
2
解决办法
9447
查看次数

尝试从symfony2抓取工具中选择表单时出错?

我一直收到以下错误:

There was 1 error:

1) Caremonk\MainSiteBundle\Tests\Controller\SecurityControllerFunctionalTest::testIndex
InvalidArgumentException: The current node list is empty.
Run Code Online (Sandbox Code Playgroud)

但是当我导航到localhost/login时,我的表单会填充正确的内容.这条线说......

$form = $crawler->selectButton('login')->form();
Run Code Online (Sandbox Code Playgroud)

导致错误.我的考试有什么问题?

功能测试:

<?php

namespace Caremonk\MainSiteBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class SecurityControllerFunctionalTest extends WebTestCase
{
    public function testIndex()
    {
        $client = static::createClient();

        $crawler = $client->request('GET', '/login');

        $form = $crawler->selectButton('login')->form();
        $form['username'] = 'testActive';
        $form['password'] = 'passwordActive';
    }
}
Run Code Online (Sandbox Code Playgroud)

树枝视图:

{# src/Acme/SecurityBundle/Resources/views/Security/login.html.twig #}
{% if error %}
    <div>{{ error.message }}</div>
{% endif %}

<form action="{{ path('caremonk_mainsite_login_check') }}" method="post">
    <label for="username">Username:</label>
    <input type="text" id="username" name="_username" value="{{ last_username }}" …
Run Code Online (Sandbox Code Playgroud)

php testing phpunit unit-testing symfony

6
推荐指数
2
解决办法
4938
查看次数

检测Angularjs中的Mousedown事件

我知道如何在单击的指令上检测mousedown事件.但是,当鼠标在我的指令/元素之外时,我的指令也需要变得不可原谅或取消选择.我怎样才能做到这一点?

javascript angularjs angularjs-directive

6
推荐指数
1
解决办法
6328
查看次数