首页 \ 问答 \ __construct的可见性(Visibility of __construct)

__construct的可见性(Visibility of __construct)

如果我有:

abstract class AbstractSingleton
{
    protected static $instance;

    public static function & getInstance()
    {
        if(null === static::$instance) static::$instance = new static();
        return static::$instance;
    }

    protected function __construct() { }
}

扩展该类的用户是否可以重新定义__construct的可见性?

class Singleton extends AbstractSingleton
{
    public function __construct() { } // That would be a problem
}

第二个问题,如果在AbstractSingleton中__construct被定义为私有,那么子类会发生什么? 有没有构造函数? 是否为该类提供了一个新的默认构造函数,如果是,具有何种可见性?


If I have:

abstract class AbstractSingleton
{
    protected static $instance;

    public static function & getInstance()
    {
        if(null === static::$instance) static::$instance = new static();
        return static::$instance;
    }

    protected function __construct() { }
}

Can a user who extends the class redefine the visibility of __construct?

class Singleton extends AbstractSingleton
{
    public function __construct() { } // That would be a problem
}

And second question, what happens for subclasses if __construct is defined as private in AbstractSingleton? Is there not constructor at all? Is a new default constructor provided to the class, and if yes, with what visibility?


原文:https://stackoverflow.com/questions/13711764
更新时间:2023-11-11 18:11

最满意答案

它观察套接字,如果在一段时间内没有信号,则返回0以关闭套接字。

为什么?

我想我需要这个代码来检测意外的用户断开连接或数据损坏(客户端发送100个字节,但服务器收到90个字节,然后服务器将等待最后10个字节不会到达)。

你没有。 您将获得另一个读取事件,其中读取将返回0,指示EOS或错误事件。

如果你想实现一个不活动超时,你必须在主选择循环中实现它。 也就是说,要记住每个套接字的最后一次活动时间,如果它太长,关闭套接字或做任何你必须做的事情。 在迭代并再次调用select()之前,将此测试放在select()循环的底部。

目前,每个读取事件在超时时间内都会阻塞所有其他select()事件。 所以你的整个服务器被阻止。


It watches the socket and if there is no signal for a certain amount of time then it returns 0 to close the socket.

Why?

I thought I need this code to detectever unexpected user disconnection or data corruption (client sent 100 bytes but server received 90 bytes then the server will wait for the last 10 bytes which won't arrive).

You don't. You will get another read event where the read will return 0 indicating EOS, or an error event.

If you want to implement an inactivity timeout you have to implement it in the main select loop. That is, keep track of the last activity time for each socket, and if it gets too long close the socket or do whatever you have to do. Put this testing at the bottom of the select() loop, before you iterate and call select() again.

At the moment every read event is blocking all other select() events for the timeout duration. So your entire server is blocked.

相关问答

更多
  • 以下是我对你所描述的内容的处理方式: Common (shared logic, utility) | Model (Business objects, pocos) | DAL (Entity Framework -- DbContext definition of ...
  • 它观察套接字,如果在一段时间内没有信号,则返回0以关闭套接字。 为什么? 我想我需要这个代码来检测意外的用户断开连接或数据损坏(客户端发送100个字节,但服务器收到90个字节,然后服务器将等待最后10个字节不会到达)。 你没有。 您将获得另一个读取事件,其中读取将返回0,指示EOS或错误事件。 如果你想实现一个不活动超时,你必须在主选择循环中实现它。 也就是说,要记住每个套接字的最后一次活动时间,如果它太长,关闭套接字或做任何你必须做的事情。 在迭代并再次调用select()之前,将此测试放在select( ...
  • 你的ev.data是一个联盟。 您可以使用fd成员,但您不必这样做。 您还可以在其中粘贴其他数据。 ev.data的重点当然是事件触发时你得到的数据,所以你需要一些方法将它与原始文件描述符联系起来。 将该文件描述符写入fd变体是实现该目标的一种简单方法,但存在其他解决方案。 一个流行的例子是定义一个抽象class Fd ,从中为特定目的从中派生具体类,然后将转换为void* ev.data.ptr基指针写入ev.data.ptr 。 收到事件后,将ev.data.ptr回Fd*并调用合适的虚拟成员函数来处理 ...
  • 这是相当模糊的文本,但我想这只是如果描述符在其他地方close ,它会被静默地从集合中删除。 从Linux联机帮助页, epoll(7) : Q6关闭文件描述符会导致它自动从所有epoll集中删除吗? A6是的,但要注意以下几点。 文件描述符是对打开文件描述的引用(参见open(2) )。 每当通过dup(2) , dup2(2) , fcntl(2) F_DUPFD或fork(2)复制描述符时,就会创建一个新的文件描述符,引用相同的打开文件描述。 打开的文件描述将继续存在,直到引用它的所有文件描述符都已关 ...
  • 你没有发布你的代码,所以我猜它可能会归结为这样的东西: import signal from bottle import route, run def my_handler(*args): print 'in signal handler', args signal.signal(signal.SIGUSR1, my_handler) @route('/hello') def hello(): return "Hello World!\n" run(host='localhost', ...
  • 您可以向该线程发送一个信号,以阻止对epoll_wait()的阻止呼叫。 如果这样做修改你的代码,像这样: while(m_WorkerRunning) { int result = epoll_wait(m_EpollDescriptor, events, MAXEVENTS, -1); if (-1 == result) { if (EINTR == errno) { /* Handle shutdown request here. */ brea ...
  • 虽然我知道你不能摆脱子查询中不同列的GROUP BY ,但可以使系统更容易。 目前你有 S.StageNumber, S.StageName, MONTH(TimeIn), DATENAME(MONTH,TimeIn), YEAR(TimeIn) 我猜想有相当多的数据要通过。 让我猜一猜: S.StageNumber, -- int, 4 bytes S.StageName, -- string, 20 bytes MONTH(TimeIn), -- int, 4 bytes DATENAME(M ...
  • Orel给了我答案,但我想我会发布完整的代码解决方案。 代替 close(fd) 我用 shutdown(fd,SHUT_RDWR); FDS[FDSL++] = fd; shutdown可防止读取或写入数据,但不会实际关闭套接字。 FDS[FDSL++] = fd; 存储fd,以便在n个事件完成之后,可以在while(FDSL)close(FDS[--FDSL]; int FDS[MAXEVENTS],FDSL=0; struct epoll_event *events = calloc(MAXEVE ...
  • 尝试运行Firebug的代码分析器 ,看看哪些功能正在减少。 基本上,点击“配置文件”按钮,刷新页面,让它加载,然后再次点击“配置文件”按钮,以读取消耗最多资源或花费最长时间的内容。 分析器应该让您了解正在发生的事情:它是在您的代码中还是在jQuery UI中。 在更一般的意义上,请确保您使用有效的选择器来选择绑定日期选择器的元素。 此外,日期选择器是否有可能将某些东西注入到瓶颈中(样式表,图像等)是瓶颈(因为我使用jQuery UI的日期选择器已经有一段时间了,所以这可能不是问题)? dfa had it ...
  • 我相信你可以用numpy.repeat(multiColAry[:, 0], multiColAry[:, 2])替换你的for循环,这应该会产生很大的不同。 此外,numpy数组通常是索引array[i, j, k]而不是array[i][j][k] ,在这种情况下结果应该是相同的但在某些情况下,后者实际上会给你错误的结果。 在任何一种情况下,前者应该更快。 最后,在使用numpy进行编程时,不鼓励使用元素操作和for循环。 而是鼓励代码以阵列方式或“矢量化”代码。 在这个范例中,您将程序表示为数组的操作 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。