r59193 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59192‎ | r59193 | r59194 >
Date:06:21, 18 November 2009
Author:tstarling
Status:deferred
Tags:
Comment:
Fixed corruption of long UDP debug log messages by using socket_sendto() instead of fsockopen() with fwrite(). Using fwrite() causes the message to be split up into 8KB async send() calls, and whether they end up in the same UDP packet just depends on timing.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -411,13 +411,18 @@
412412 // IPv6 bracketed host
413413 $protocol = $m[1];
414414 $host = $m[2];
415 - $port = $m[3];
 415+ $port = intval( $m[3] );
416416 $prefix = isset( $m[4] ) ? $m[4] : false;
 417+ $domain = AF_INET6;
417418 } elseif ( preg_match( '!^(tcp|udp):(?://)?([a-zA-Z0-9.-]+):(\d+)(?:/(.*))?$!', $file, $m ) ) {
418419 $protocol = $m[1];
419420 $host = $m[2];
420 - $port = $m[3];
 421+ if ( !IP::isIPv4( $host ) ) {
 422+ $host = gethostbyname( $host );
 423+ }
 424+ $port = intval( $m[3] );
421425 $prefix = isset( $m[4] ) ? $m[4] : false;
 426+ $domain = AF_INET;
422427 } else {
423428 throw new MWException( __METHOD__.": Invalid UDP specification" );
424429 }
@@ -429,12 +434,12 @@
430435 }
431436 }
432437
433 - $sock = fsockopen( "$protocol://$host", $port );
 438+ $sock = socket_create( $domain, SOCK_DGRAM, SOL_UDP );
434439 if ( !$sock ) {
435440 return;
436441 }
437 - fwrite( $sock, $text );
438 - fclose( $sock );
 442+ socket_sendto( $sock, $text, strlen( $text ), 0, $host, $port );
 443+ socket_close( $sock );
439444 } else {
440445 wfSuppressWarnings();
441446 $exists = file_exists( $file );
Index: trunk/phase3/RELEASE-NOTES
@@ -638,6 +638,8 @@
639639 * (bug 21455) Fixed "Watch this page" checkbox appearing on some special pages
640640 even to non-logged in users
641641 * (bug 21551) Make Squid reponse limit configurable
 642+* Fixed corruption of long UDP debug log messages by using socket_sendto()
 643+ instead of fsockopen() with fwrite().
642644
643645 == API changes in 1.16 ==
644646

Status & tagging log