MadelineProto/src/Socket.php
Daniil Gentili 915a0cd180 Clickable buttons, thread safety (#119)
* I'll just leave this here

* Threading fixes

* Apply fixes from StyleCI

* Composer fixes

* Lots of threading fixes, included all RSA keys

* Apply fixes from StyleCI

* Updated phpseclib

* fixes

* Apply fixes from StyleCI

* final fixes

* git add -A

* Apply fixes from StyleCI

* bugfix

* Fixes

* Apply fixes from StyleCI

* Small fixes

* Final fixes

* Speed improvements

* speed fixes

* Apply fixes from StyleCI

* This is faster than sanic

* Apply fixes from StyleCI

* Final speed fixes

* Apply fixes from StyleCI

* Less logging

* Speed+++

* Apply fixes from StyleCI

* More fixes

* Bug74586Exception

* Apply fixes from StyleCI

* Fixes

* Lemme fix that dumb-ass bug that broke everything

* Apply fixes from StyleCI

* Updated rollbar token

* Fixes for other tcp_* protocols

* Apply fixes from StyleCI

* No need for phpstruct anymore

* Add a conflict (OH NOES pony warfare)

* Less logs, beginning of clickable buttons

* Apply fixes from StyleCI

* Bugfixes, fixed clickable buttons

* Apply fixes from StyleCI

* Better errors

* Apply fixes from StyleCI

* You can now click text buttons

* Apply fixes from StyleCI
2017-05-16 15:12:04 +02:00

53 lines
1.8 KiB
PHP

<?php
/*
Copyright 2016-2017 Daniil Gentili
(https://daniil.it)
This file is part of MadelineProto.
MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License along with MadelineProto.
If not, see <http://www.gnu.org/licenses/>.
*/
if (!extension_loaded('pthreads')) {
class Socket
{
public function __construct(int $domain, int $type, int $protocol)
{
$this->sock = socket_create($domain, $type, $protocol);
}
public function setBlocking(bool $blocking)
{
if ($blocking) {
return socket_set_block($this->sock);
}
return socket_set_nonblock($this->sock);
}
public function setOption(int $level, int $name, $value)
{
if (in_array($name, [\SO_RCVTIMEO, \SO_SNDTIMEO])) {
$value = ['sec' => (int) $value, 'usec' => (int) (($value - (int) $value) * 1000000)];
}
return socket_set_option($this->sock, $level, $name, $value);
}
public function getOption(int $level, int $name)
{
return socket_get_option($this->sock, $level, $name);
}
public function __call($name, $args)
{
$name = 'socket_'.$name;
array_unshift($args, $this->sock);
return $name(...$args);
}
}
}