diff --git a/core/sendfile.c b/core/sendfile.c index e81bc8ca..999e22a7 100644 --- a/core/sendfile.c +++ b/core/sendfile.c @@ -68,6 +68,10 @@ static void uwsgi_offload_close(struct uwsgi_offload_request *uor) { next->prev = prev; } + if (uor->buf) { + free(uor->buf); + } + free(uor); } @@ -139,8 +143,40 @@ static void uwsgi_offload_loop(struct uwsgi_thread *ut) { if (errno == EAGAIN) continue; uwsgi_error("sendfile()"); } - uwsgi_offload_close(uor); +#else + if (!uor->buf) { + uor->buf = uwsgi_malloc(32768); + } + if (uor->to_write == 0) { + ssize_t len = read(uor->fd, uor->buf, 32768); + if (len > 0) { + uor->to_write = len; + uor->buf_pos = 0; + continue; + } + else if (len < 0) { + uwsgi_error("read()"); + } + uwsgi_offload_close(uor); + continue; + } + ssize_t len = write(uor->s, uor->buf + uor->buf_pos, uor->to_write - uor->buf_pos); + if (len > 0) { + uor->written += len; + uor->to_write -= len; + uor->buf_pos += len; + if (uor->written >= uor->len) { + uwsgi_offload_close(uor); + } + continue; + } + else if (len < 0) { + if (errno == EAGAIN) continue; + uwsgi_error("write()"); + } + #endif + uwsgi_offload_close(uor); } } } diff --git a/plugins/alarm_speech/alarm_speech.m b/plugins/alarm_speech/alarm_speech.m new file mode 100644 index 00000000..934c5c21 --- /dev/null +++ b/plugins/alarm_speech/alarm_speech.m @@ -0,0 +1,52 @@ +#include "../../uwsgi.h" +#import "Foundation/NSString.h" +#import "AppKit/NSSpeechSynthesizer.h" + +@interface uWSGIAlarmSpeaker : NSObject { + NSSpeechSynthesizer *synth; +} + +-(void)speak: (NSString *)phrase; + +@end + + +@implementation uWSGIAlarmSpeaker + +- (uWSGIAlarmSpeaker *) init { + self = [super init]; + synth = [[NSSpeechSynthesizer alloc] initWithVoice:nil]; + return self; +} + +- (void)speak:(NSString *)phrase { + [synth startSpeakingString:phrase]; +} + +@end + +// generate a uwsgi signal on alarm +void uwsgi_alarm_speech_init(struct uwsgi_alarm_instance *uai) { + uai->data_ptr = [[uWSGIAlarmSpeaker alloc] init]; +} + +void uwsgi_alarm_speech_func(struct uwsgi_alarm_instance *uai, char *msg, size_t len) { + uWSGIAlarmSpeaker *say = (uWSGIAlarmSpeaker *) uai->data_ptr; + NSString *phrase = [[NSString alloc] initWithBytes:msg + length:len + encoding:NSUTF8StringEncoding]; + + [say speak:phrase]; + [phrase release]; + +} + +static void uwsgi_alarm_speech_load(void) { + uwsgi_register_alarm("speech", uwsgi_alarm_speech_init, uwsgi_alarm_speech_func); +} + +struct uwsgi_plugin alarm_speech_plugin = { + .name = "alarm_speech", + .on_load = uwsgi_alarm_speech_load, +}; + diff --git a/plugins/alarm_speech/uwsgiplugin.py b/plugins/alarm_speech/uwsgiplugin.py new file mode 100644 index 00000000..fef16eb1 --- /dev/null +++ b/plugins/alarm_speech/uwsgiplugin.py @@ -0,0 +1,6 @@ +NAME='alarm_speech' + +CFLAGS = [] +LDFLAGS = [] +LIBS = ['-framework appkit'] +GCC_LIST = ['alarm_speech.m'] diff --git a/uwsgi.h b/uwsgi.h index b52e4653..9288db00 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -3333,6 +3333,9 @@ struct uwsgi_offload_request { int s; int fd; off_t pos; + char *buf; + off_t buf_pos; + size_t to_write; size_t len; size_t written; struct uwsgi_offload_request *prev;