Changeset 1307
- Timestamp:
- 10/16/09 01:54:04 (6 weeks ago)
- Files:
-
- 1 modified
-
trunk/server/lib/mogdeps/Danga/Socket.pm (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/lib/mogdeps/Danga/Socket.pm
r1087 r1307 101 101 102 102 use vars qw{$VERSION}; 103 $VERSION = "1. 57";103 $VERSION = "1.61"; 104 104 105 105 use warnings; … … 113 113 'write_buf_offset', # offset into first array of write_buf to start writing at 114 114 'write_buf_size', # total length of data in all write_buf items 115 'write_set_watch', # bool: true if we internally set watch_write rather than by a subclass 115 116 'read_push_back', # arrayref of "pushed-back" read data the application didn't want 116 117 'closed', # bool: socket is closed 117 118 'corked', # bool: socket is corked 118 119 'event_watch', # bitmask of events the client is interested in (POLLIN,OUT,etc.) 120 'peer_v6', # bool: cached; if peer is an IPv6 address 119 121 'peer_ip', # cached stringified IP address of $sock 120 122 'peer_port', # cached port number of $sock … … 186 188 $DoneInit = 0; 187 189 190 POSIX::close($Epoll) if defined $Epoll && $Epoll >= 0; 191 POSIX::close($KQueue) if defined $KQueue && $KQueue >= 0; 192 188 193 *EventLoop = *FirstTimeEventLoop; 189 194 } … … 1037 1042 $self->{write_buf_size} += $len; 1038 1043 } 1044 $self->{write_set_watch} = 1 unless $self->{event_watch} & POLLOUT; 1039 1045 $self->watch_write(1); 1040 1046 return 0; … … 1064 1070 $self->{write_buf_offset} = 0; 1065 1071 1072 if ($self->{write_set_watch}) { 1073 $self->watch_write(0); 1074 $self->{write_set_watch} = 0; 1075 } 1076 1066 1077 # this was our only write, so we can return immediately 1067 1078 # since we avoided incrementing the buffer size or … … 1080 1091 sub on_incomplete_write { 1081 1092 my Danga::Socket $self = shift; 1093 $self->{write_set_watch} = 1 unless $self->{event_watch} & POLLOUT; 1082 1094 $self->watch_write(1); 1083 1095 } … … 1227 1239 $event |= POLLOUT if $val; 1228 1240 1241 if ($val && caller ne __PACKAGE__) { 1242 # A subclass registered interest, it's now responsible for this. 1243 $self->{write_set_watch} = 0; 1244 } 1245 1229 1246 # If it changed, set it 1230 1247 if ($event != $self->{event_watch}) { … … 1289 1306 1290 1307 my ($port, $iaddr) = eval { 1291 Socket::sockaddr_in($pn); 1308 if (length($pn) >= 28) { 1309 return Socket6::unpack_sockaddr_in6($pn); 1310 } else { 1311 return Socket::sockaddr_in($pn); 1312 } 1292 1313 }; 1293 1314 … … 1299 1320 $self->{peer_port} = $port; 1300 1321 1301 return $self->{peer_ip} = Socket::inet_ntoa($iaddr); 1322 if (length($iaddr) == 4) { 1323 return $self->{peer_ip} = Socket::inet_ntoa($iaddr); 1324 } else { 1325 $self->{peer_v6} = 1; 1326 return $self->{peer_ip} = Socket6::inet_ntop(Socket6::AF_INET6(), 1327 $iaddr); 1328 } 1302 1329 } 1303 1330 … … 1310 1337 sub peer_addr_string { 1311 1338 my Danga::Socket $self = shift; 1312 my $ip = $self->peer_ip_string; 1313 return $ip ? "$ip:$self->{peer_port}" : undef; 1339 my $ip = $self->peer_ip_string 1340 or return undef; 1341 return $self->{peer_v6} ? 1342 "[$ip]:$self->{peer_port}" : 1343 "$ip:$self->{peer_port}"; 1314 1344 } 1315 1345
