@@ -61,7 +61,8 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
6161 php_stream_transport_factory factory = NULL ;
6262 const char * p , * protocol = NULL ;
6363 size_t n = 0 ;
64- int failed = 0 ;
64+ bool failed = false;
65+ bool bailout = false;
6566 zend_string * error_text = NULL ;
6667 struct timeval default_timeout = { 0 , 0 };
6768
@@ -131,61 +132,63 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
131132 (char * )name , namelen , persistent_id , options , flags , timeout ,
132133 context STREAMS_REL_CC );
133134
134- zend_begin_record_errors_without_emitting ();
135-
136135 if (stream ) {
137- php_stream_context_set (stream , context );
136+ zend_try {
137+ php_stream_context_set (stream , context );
138138
139- if ((flags & STREAM_XPORT_SERVER ) == 0 ) {
140- /* client */
139+ if ((flags & STREAM_XPORT_SERVER ) == 0 ) {
140+ /* client */
141141
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 )) {
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 )) {
146146
147- ERR_RETURN (error_string , error_text , "connect() failed: %s" );
147+ ERR_RETURN (error_string , error_text , "connect() failed: %s" );
148148
149- failed = 1 ;
150- }
151- }
152-
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 = 1 ;
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 );
149+ failed = true;
165150 }
151+ }
166152
167- if (0 != php_stream_xport_listen (stream , backlog , & error_text )) {
168- ERR_RETURN (error_string , error_text , "listen() failed: %s" );
169- 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+ }
170171 }
171172 }
172173 }
173- }
174+ } zend_catch {
175+ bailout = true;
176+ } zend_end_try ();
174177 }
175178
176- if (failed ) {
179+ if (failed || bailout ) {
177180 /* failure means that they don't get a stream to play with */
178181 if (persistent_id ) {
179182 php_stream_pclose (stream );
180183 } else {
181184 php_stream_close (stream );
182185 }
183186 stream = NULL ;
187+ if (bailout ) {
188+ zend_bailout ();
189+ }
184190 }
185191
186- zend_emit_recorded_errors ();
187- zend_free_recorded_errors ();
188-
189192 return stream ;
190193}
191194
0 commit comments