POSIX是否有任何“DisconnectEx”的等价物?

时间:2018-01-14 16:07:09

标签: c++ c sockets winapi posix

由Windows API提供的

DisconnectEx允许您断开套接字并将其重新用于新的基于套接字的连接。这样就可以构建套接字池来提高性能。

POSIX有没有相应的东西?从它的外观来看,它没有一个。您被迫关闭套接字(使用<?php if($_POST && isset($_FILES['file'])) { $recipient_email = "mymail@gmail.com"; //recepient $from_email = "mymail2@gmail.com"; //from email using site domain. $subject = "Attachment email from your website!"; //email subject line $sender_name = filter_var($_POST["s_name"], FILTER_SANITIZE_STRING); //capture sender name $sender_number = filter_var($_POST["s_number"], FILTER_SANITIZE_STRING); //capture sender number $sender_email = filter_var($_POST["s_email"], FILTER_SANITIZE_STRING); //capture sender email $sender_message = filter_var($_POST["s_message"], FILTER_SANITIZE_STRING); //capture message $attachments = $_FILES['file']; //php validation if(strlen($sender_name)<4){ die('Name is too short or empty'); } if(strlen($sender_number)<4){ die('Number is too short or empty'); } if (!filter_var($sender_email, FILTER_VALIDATE_EMAIL)) { die('Invalid email'); } if(strlen($sender_message)<4){ die('Too short message! Please enter something'); } $file_count = count($attachments['name']); //count total files attached $boundary = md5(""); if($file_count > 0){ //if attachment exists //header $headers = "MIME-Version: 1.0\r\n"; $headers .= "From:".$from_email."\r\n"; $headers .= "Reply-To: ".$sender_email."" . "\r\n"; $headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n"; //message text $body = "--$boundary\r\n"; $body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n"; $body .= "Content-Transfer-Encoding: base64\r\n\r\n"; $body .= chunk_split(base64_encode($sender_name)) . "<br />"; $body .= chunk_split(base64_encode($sender_number)) . "<br />"; $body .= chunk_split(base64_encode($sender_message)) . "<br />"; //attachments for ($x = 0; $x < $file_count; $x++){ if(!empty($attachments['name'][$x])){ if($attachments['error'][$x]>0) //exit script and output error if we encounter any { $mymsg = array( 1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini", 2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 3=>"The uploaded file was only partially uploaded", 4=>"No file was uploaded", 6=>"Missing a temporary folder" ); die($mymsg[$attachments['error'][$x]]); } //get file info $file_name = $attachments['name'][$x]; $file_size = $attachments['size'][$x]; $file_type = $attachments['type'][$x]; //read file $handle = fopen($attachments['tmp_name'][$x], "r"); $content = fread($handle, $file_size); fclose($handle); $encoded_content = chunk_split(base64_encode($content)); //split into smaller chunks (RFC 2045) $body .= "--$boundary\r\n"; $body .="Content-Type: $file_type; name=" . $file_name ."\r\n"; $body .="Content-Disposition: attachment; filename=" . $file_name ."\r\n"; $body .="Content-Transfer-Encoding: base64\r\n"; $body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n"; $body .= $encoded_content; } } }else{ //send plain email otherwise $headers = "From:".$from_email."\r\n". "Reply-To: ".$sender_email. "\n" . "X-Mailer: PHP/" . phpversion(); $body = $sender_name. "\n"; $body = $sender_number. "\n"; $body = $sender_message. "\n"; } $sentMail = @mail($recipient_email, $subject, $body, $headers); if($sentMail) //output success or failure messages { header("Location: index.php"); /* Redirect browser */ exit(); }else{ header("Location: index.php"); /* Redirect browser */ } } ?> closesocket)并在需要时请求新套接字。也许在UNIX操作系统中创建套接字是如此便宜,不值得实现这种功能,但我无法证明它。

0 个答案:

没有答案