mirror of
https://github.com/deuill/go-php.git
synced 2024-09-21 08:50:45 +00:00
Move context write method to context.c
.
This commit is contained in:
parent
bd0f41e3d5
commit
403a114ef2
10
context.c
10
context.c
@ -10,6 +10,7 @@
|
||||
// Local includes.
|
||||
#include "engine.h"
|
||||
#include "context.h"
|
||||
#include "_cgo_export.h"
|
||||
|
||||
engine_context *context_new(php_engine *engine, void *parent) {
|
||||
engine_context *context;
|
||||
@ -60,6 +61,15 @@ void context_exec(engine_context *context, char *filename) {
|
||||
return_multi(NULL, 0);
|
||||
}
|
||||
|
||||
int context_write(engine_context *context, const char *message, unsigned int length) {
|
||||
int written = contextWrite(context->parent, (void *) message, length);
|
||||
if (written != length) {
|
||||
php_handle_aborted_connection();
|
||||
}
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
void context_destroy(engine_context *context) {
|
||||
php_request_shutdown((void *) 0);
|
||||
|
||||
|
@ -35,12 +35,12 @@ func (c *Context) Destroy() {
|
||||
}
|
||||
|
||||
//export contextWrite
|
||||
func contextWrite(ctxptr unsafe.Pointer, buffer unsafe.Pointer, length C.int) C.int {
|
||||
func contextWrite(ctxptr unsafe.Pointer, buffer unsafe.Pointer, length C.uint) C.int {
|
||||
context := (*Context)(ctxptr)
|
||||
|
||||
written, err := context.writer.Write(C.GoBytes(buffer, length))
|
||||
written, err := context.writer.Write(C.GoBytes(buffer, C.int(length)))
|
||||
if err != nil {
|
||||
return C.int(0)
|
||||
return C.int(-1)
|
||||
}
|
||||
|
||||
return C.int(written)
|
||||
|
@ -8,6 +8,7 @@ typedef struct _engine_context {
|
||||
|
||||
engine_context *context_new(php_engine *engine, void *parent);
|
||||
void context_exec(engine_context *context, char *filename);
|
||||
int context_write(engine_context *context, const char *message, unsigned int length);
|
||||
void context_destroy(engine_context *context);
|
||||
|
||||
#endif
|
9
engine.c
9
engine.c
@ -12,7 +12,6 @@
|
||||
// Local includes.
|
||||
#include "engine.h"
|
||||
#include "context.h"
|
||||
#include "_cgo_export.h"
|
||||
|
||||
const char engine_ini_defaults[] =
|
||||
"html_errors = 0\n"
|
||||
@ -25,13 +24,7 @@ const char engine_ini_defaults[] =
|
||||
|
||||
static int engine_ub_write(const char *str, uint str_length TSRMLS_DC) {
|
||||
engine_context *context = (engine_context *) SG(server_context);
|
||||
|
||||
int written = contextWrite(context->parent, (void *) str, str_length);
|
||||
if (written != str_length) {
|
||||
php_handle_aborted_connection();
|
||||
}
|
||||
|
||||
return str_length;
|
||||
return context_write(context, str, str_length);
|
||||
}
|
||||
|
||||
static void engine_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC) {
|
||||
|
Loading…
Reference in New Issue
Block a user