… | |
… | |
75 | |
75 | |
76 | sub readable { &Coro::Handle::FH::readable } |
76 | sub readable { &Coro::Handle::FH::readable } |
77 | sub writable { &Coro::Handle::FH::writable } |
77 | sub writable { &Coro::Handle::FH::writable } |
78 | |
78 | |
79 | BEGIN { |
79 | BEGIN { |
80 | our $VERSION = '0.1'; |
80 | our $VERSION = '0.2'; |
81 | |
81 | |
82 | require XSLoader; |
82 | require XSLoader; |
83 | XSLoader::load Coro::Mysql::, $VERSION; |
83 | XSLoader::load Coro::Mysql::, $VERSION; |
84 | } |
84 | } |
85 | |
85 | |
… | |
… | |
89 | so it becomes compatible to Coro threads. |
89 | so it becomes compatible to Coro threads. |
90 | |
90 | |
91 | After that, it returns the patched handle - you should always use the |
91 | After that, it returns the patched handle - you should always use the |
92 | newly returned database handle. |
92 | newly returned database handle. |
93 | |
93 | |
|
|
94 | It is safe to call this function on any database handle, but it will only |
|
|
95 | do anything to L<DBD::mysql> handles, others are returned unchanged. |
|
|
96 | |
94 | =cut |
97 | =cut |
95 | |
98 | |
96 | sub unblock { |
99 | sub unblock { |
97 | my ($DBH) = @_; |
100 | my ($DBH) = @_; |
98 | my $sock = $DBH->{sock}; |
|
|
99 | |
101 | |
100 | open my $fh, "+>&" . $DBH->{sockfd} |
102 | if ($DBH->{Driver}{Name} eq "mysql") { |
101 | or croak "Coro::Mysql unable to clone mysql fd"; |
103 | my $sock = $DBH->{sock}; |
102 | |
104 | |
103 | $fh = Coro::Handle::unblock $fh; |
105 | open my $fh, "+>&" . $DBH->{sockfd} |
|
|
106 | or croak "Coro::Mysql unable to clone mysql fd"; |
104 | |
107 | |
|
|
108 | $fh = Coro::Handle::unblock $fh; |
|
|
109 | |
105 | _patch $sock, $DBH->{sockfd}, tied ${$fh}; |
110 | _patch $sock, $DBH->{sockfd}, tied ${$fh}; |
106 | $DBH->{private_Coro_Mysql} = guard { |
111 | $DBH->{private_Coro_Mysql} = guard { |
107 | _unpatch $sock; |
112 | _unpatch $sock; |
108 | undef $fh; |
113 | undef $fh; |
|
|
114 | }; |
109 | }; |
115 | } |
110 | |
116 | |
111 | $DBH |
117 | $DBH |
112 | } |
118 | } |
113 | |
119 | |
114 | 1; |
120 | 1; |