__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
最满意答案
它观察套接字,如果在一段时间内没有信号,则返回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.
相关问答
更多-
软件架构问题(Software architecture issue)[2021-08-14]
以下是我对你所描述的内容的处理方式: Common (shared logic, utility) | Model (Business objects, pocos) | DAL (Entity Framework -- DbContext definition of ... -
它观察套接字,如果在一段时间内没有信号,则返回0以关闭套接字。 为什么? 我想我需要这个代码来检测意外的用户断开连接或数据损坏(客户端发送100个字节,但服务器收到90个字节,然后服务器将等待最后10个字节不会到达)。 你没有。 您将获得另一个读取事件,其中读取将返回0,指示EOS或错误事件。 如果你想实现一个不活动超时,你必须在主选择循环中实现它。 也就是说,要记住每个套接字的最后一次活动时间,如果它太长,关闭套接字或做任何你必须做的事情。 在迭代并再次调用select()之前,将此测试放在select( ...
-
使用linux epoll:epoll_ctl似乎有冗余参数?(Using linux epoll: epoll_ctl seems to have redundant parameter?)[2022-06-19]
你的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 ...
-
瓶颈在SORT操作(Bottle neck on SORT operation)[2021-10-22]
虽然我知道你不能摆脱子查询中不同列的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循环。 而是鼓励代码以阵列方式或“矢量化”代码。 在这个范例中,您将程序表示为数组的操作 ...