正在显示
1 个修改的文件
包含
29 行增加
和
1 行删除
| @@ -93,7 +93,35 @@ class ImapClient { | @@ -93,7 +93,35 @@ class ImapClient { | ||
| 93 | if($this->debug){ | 93 | if($this->debug){ |
| 94 | echo 'write: '.$cmd; | 94 | echo 'write: '.$cmd; |
| 95 | } | 95 | } |
| 96 | - return fwrite($this->socket,$cmd); | 96 | + |
| 97 | + $totalBytes = strlen($cmd); | ||
| 98 | + $bytesWritten = 0; | ||
| 99 | + $maxW = 50; | ||
| 100 | + while ($bytesWritten < $totalBytes) { | ||
| 101 | + $result = fwrite($this->socket, substr($cmd, $bytesWritten)); | ||
| 102 | + // 写失败了 | ||
| 103 | + if ($result === false) { return false; } | ||
| 104 | + | ||
| 105 | + // 更新已写入的字节数 | ||
| 106 | + $bytesWritten += $result; | ||
| 107 | + | ||
| 108 | + // 如果没有写入任何字节,可能是缓冲区满了,稍后再试 | ||
| 109 | + if ($result === 0) { | ||
| 110 | + $maxW--; | ||
| 111 | + if(!$maxW){ | ||
| 112 | + throw new \Exception('socket write error time out'); | ||
| 113 | + } | ||
| 114 | + // 兼容下swoole | ||
| 115 | + if(function_exists('go') && \co::getCid()>0){ | ||
| 116 | + \co::sleep(0.1); | ||
| 117 | + }else{ | ||
| 118 | + // 等待 100 毫秒 | ||
| 119 | + usleep(100000); | ||
| 120 | + } | ||
| 121 | + } | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + return $bytesWritten; | ||
| 97 | } | 125 | } |
| 98 | 126 | ||
| 99 | /** | 127 | /** |
-
请 注册 或 登录 后发表评论