@@ -61,7 +61,8 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
61
61
php_stream_transport_factory factory = NULL ;
62
62
const char * p , * protocol = NULL ;
63
63
size_t n = 0 ;
64
- int failed = 0 ;
64
+ bool failed = false;
65
+ bool bailout = false;
65
66
zend_string * error_text = NULL ;
66
67
struct timeval default_timeout = { 0 , 0 };
67
68
@@ -132,53 +133,60 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
132
133
context STREAMS_REL_CC );
133
134
134
135
if (stream ) {
135
- php_stream_context_set (stream , context );
136
+ zend_try {
137
+ php_stream_context_set (stream , context );
136
138
137
- if ((flags & STREAM_XPORT_SERVER ) == 0 ) {
138
- /* client */
139
+ if ((flags & STREAM_XPORT_SERVER ) == 0 ) {
140
+ /* client */
139
141
140
- if (flags & (STREAM_XPORT_CONNECT |STREAM_XPORT_CONNECT_ASYNC )) {
141
- if (-1 == php_stream_xport_connect (stream , name , namelen ,
142
- flags & STREAM_XPORT_CONNECT_ASYNC ? 1 : 0 ,
143
- timeout , & error_text , error_code )) {
142
+ if (flags & (STREAM_XPORT_CONNECT |STREAM_XPORT_CONNECT_ASYNC )) {
143
+ if (-1 == php_stream_xport_connect (stream , name , namelen ,
144
+ flags & STREAM_XPORT_CONNECT_ASYNC ? 1 : 0 ,
145
+ timeout , & error_text , error_code )) {
144
146
145
- ERR_RETURN (error_string , error_text , "connect() failed: %s" );
147
+ ERR_RETURN (error_string , error_text , "connect() failed: %s" );
146
148
147
- failed = 1 ;
148
- }
149
- }
150
-
151
- } else {
152
- /* server */
153
- if (flags & STREAM_XPORT_BIND ) {
154
- if (0 != php_stream_xport_bind (stream , name , namelen , & error_text )) {
155
- ERR_RETURN (error_string , error_text , "bind() failed: %s" );
156
- failed = 1 ;
157
- } else if (flags & STREAM_XPORT_LISTEN ) {
158
- zval * zbacklog = NULL ;
159
- int backlog = 32 ;
160
-
161
- if (PHP_STREAM_CONTEXT (stream ) && (zbacklog = php_stream_context_get_option (PHP_STREAM_CONTEXT (stream ), "socket" , "backlog" )) != NULL ) {
162
- backlog = zval_get_long (zbacklog );
149
+ failed = true;
163
150
}
151
+ }
164
152
165
- if (0 != php_stream_xport_listen (stream , backlog , & error_text )) {
166
- ERR_RETURN (error_string , error_text , "listen() failed: %s" );
167
- failed = 1 ;
153
+ } else {
154
+ /* server */
155
+ if (flags & STREAM_XPORT_BIND ) {
156
+ if (0 != php_stream_xport_bind (stream , name , namelen , & error_text )) {
157
+ ERR_RETURN (error_string , error_text , "bind() failed: %s" );
158
+ failed = true;
159
+ } else if (flags & STREAM_XPORT_LISTEN ) {
160
+ zval * zbacklog = NULL ;
161
+ int backlog = 32 ;
162
+
163
+ if (PHP_STREAM_CONTEXT (stream ) && (zbacklog = php_stream_context_get_option (PHP_STREAM_CONTEXT (stream ), "socket" , "backlog" )) != NULL ) {
164
+ backlog = zval_get_long (zbacklog );
165
+ }
166
+
167
+ if (0 != php_stream_xport_listen (stream , backlog , & error_text )) {
168
+ ERR_RETURN (error_string , error_text , "listen() failed: %s" );
169
+ failed = true;
170
+ }
168
171
}
169
172
}
170
173
}
171
- }
174
+ } zend_catch {
175
+ bailout = true;
176
+ } zend_end_try ();
172
177
}
173
178
174
- if (failed ) {
179
+ if (failed || bailout ) {
175
180
/* failure means that they don't get a stream to play with */
176
181
if (persistent_id ) {
177
182
php_stream_pclose (stream );
178
183
} else {
179
184
php_stream_close (stream );
180
185
}
181
186
stream = NULL ;
187
+ if (bailout ) {
188
+ zend_bailout ();
189
+ }
182
190
}
183
191
184
192
return stream ;
0 commit comments