@@ -42,7 +42,7 @@ enum Commands {
42
42
CMD_CLOSE_STDERR = 0x33 ,
43
43
};
44
44
45
- #define debug (args ...) syslog(LOG_INFO, args)
45
+ #define debug (args ...)
46
46
#define info (args ...) syslog(LOG_INFO, args)
47
47
#define error (args ...) syslog(LOG_ERR, args)
48
48
#define fatal (args ...) ({ \
@@ -66,7 +66,7 @@ struct epoll_event spid_event;
66
66
// Static array for those events to be stored
67
67
struct epoll_event events [MAX_EPOLL_EVENTS ];
68
68
69
- #define PIPE_BUF 4096
69
+ #define INTERNAL_PIPE_BUF_SIZE 32768
70
70
#define MAX_CTRL_ARGS 255
71
71
#define MAX_WRITE_LEN 255
72
72
@@ -109,7 +109,7 @@ typedef struct {
109
109
// The number of 'active' bytes
110
110
int bufcount ;
111
111
// The internal buffer used for back pressure
112
- char buffer [PIPE_BUF ];
112
+ char buffer [INTERNAL_PIPE_BUF_SIZE ];
113
113
} pipebuf_t ;
114
114
115
115
typedef struct {
@@ -252,9 +252,9 @@ int write_from_pipebuf(pipebuf_t *pb, int fd, int write_len) {
252
252
to_write = write_len ;
253
253
254
254
// If the data would go past the end of the buffer
255
- if (pb -> startpos + to_write > PIPE_BUF ) {
255
+ if (pb -> startpos + to_write > INTERNAL_PIPE_BUF_SIZE ) {
256
256
// Only write until the end of the buffer
257
- to_write = PIPE_BUF - pb -> startpos ;
257
+ to_write = INTERNAL_PIPE_BUF_SIZE - pb -> startpos ;
258
258
}
259
259
260
260
// Write this batch to the file descriptor from the internal buffer
@@ -266,7 +266,7 @@ int write_from_pipebuf(pipebuf_t *pb, int fd, int write_len) {
266
266
pb -> bufcount -= written ;
267
267
268
268
// If the start position marker is at the buffer end
269
- if (pb -> startpos == PIPE_BUF ) {
269
+ if (pb -> startpos == INTERNAL_PIPE_BUF_SIZE ) {
270
270
// Set it at the start of the buffer for the next read
271
271
pb -> startpos = 0 ;
272
272
}
@@ -421,9 +421,9 @@ int pipebuf_in_write_to_sock(pipebuf_t* pb, size_t num_to_write) {
421
421
int remaining = num_to_write - written ;
422
422
int packet_write_size = (remaining < MAX_WRITE_LEN ) ? remaining : MAX_WRITE_LEN ;
423
423
// Send the header so the CLI knows it's about to receive data
424
- send_header (CMD_WRITE_CONTROL + pb -> role , pb -> id , 0 , packet_write_size );
424
+ send_header (CMD_WRITE_CONTROL + pb -> role , pb -> id , packet_write_size >> 8 , packet_write_size & 0xFF );
425
425
// Send the data and increment the counter of the number of bytes written
426
- pipebuf_common_debug (pb , "WRiting from stdout/stderr internal to CLI" );
426
+ pipebuf_common_debug (pb , "Writing from stdout/stderr internal to CLI" );
427
427
debug ("{%d bytes}" , packet_write_size );
428
428
written += write_from_pipebuf (pb , sock_fd , packet_write_size );
429
429
}
@@ -459,7 +459,7 @@ void pipebuf_in_ack(pipebuf_t* pb, size_t ack_number_size) {
459
459
460
460
// If this pipe buffer was previously full
461
461
// But will now be able to send out data
462
- if (pb -> bufcount == PIPE_BUF && ack_size > 0 ) {
462
+ if (pb -> bufcount == INTERNAL_PIPE_BUF_SIZE && ack_size > 0 ) {
463
463
// Enable notifications of when the internal pipe buffer is written to
464
464
add_pipebuf_epoll (pb );
465
465
}
@@ -492,17 +492,17 @@ void pipebuf_in_to_internal_buffer(pipebuf_t* pb) {
492
492
else to read */
493
493
int r = 0 ;
494
494
int try_to_read = 0 ;
495
- int space_available = PIPE_BUF - pb -> bufcount ;
495
+ int space_available = INTERNAL_PIPE_BUF_SIZE - pb -> bufcount ;
496
496
pipebuf_common_debug (pb , "stdout/stderr has data from child to be read" );
497
497
// While we have space in the pipe buffer
498
498
while (space_available ) {
499
499
// Try to read the entire space
500
500
try_to_read = space_available ;
501
501
502
502
// If the space extends past the pipe buffer end
503
- if (pb -> endpos + try_to_read > PIPE_BUF ) {
503
+ if (pb -> endpos + try_to_read > INTERNAL_PIPE_BUF_SIZE ) {
504
504
// Set this read to only read up to the end
505
- try_to_read = PIPE_BUF - pb -> endpos ;
505
+ try_to_read = INTERNAL_PIPE_BUF_SIZE - pb -> endpos ;
506
506
}
507
507
508
508
pipebuf_common_debug (pb , "Attempting to write from stdout/stderr child to internal" );
@@ -524,7 +524,7 @@ void pipebuf_in_to_internal_buffer(pipebuf_t* pb) {
524
524
pb -> endpos += r ;
525
525
526
526
// If the start position marker is at the buffer end
527
- if (pb -> endpos == PIPE_BUF ) {
527
+ if (pb -> endpos == INTERNAL_PIPE_BUF_SIZE ) {
528
528
// Set it at the start of the buffer for the next read
529
529
pb -> endpos = 0 ;
530
530
}
@@ -555,7 +555,7 @@ void pipebuf_in_to_internal_buffer(pipebuf_t* pb) {
555
555
}
556
556
557
557
// If the pipe buffer is full
558
- if (pb -> bufcount == PIPE_BUF ) {
558
+ if (pb -> bufcount == INTERNAL_PIPE_BUF_SIZE ) {
559
559
// remove it from the epoll
560
560
delete_pipebuf_epoll (pb );
561
561
}
@@ -576,9 +576,9 @@ Returns: the file descriptor to communicate with the stream
576
576
int pipebuf_out_init (pipebuf_t * pb , int id , int role ) {
577
577
int fd = pipebuf_common_init (pb , id , role , EPOLLOUT , 1 );
578
578
579
- pipebuf_out_ack (pb , PIPE_BUF );
579
+ pipebuf_out_ack (pb , INTERNAL_PIPE_BUF_SIZE );
580
580
581
- pb -> credit = PIPE_BUF ;
581
+ pb -> credit = INTERNAL_PIPE_BUF_SIZE ;
582
582
583
583
return fd ;
584
584
}
@@ -621,9 +621,9 @@ void pipebuf_out_to_internal_buffer(pipebuf_t* pb, int read_len) {
621
621
to_read = read_len ;
622
622
623
623
// If this read would read further than the end of the ring buffer
624
- if (pb -> endpos + read_len > PIPE_BUF ) {
624
+ if (pb -> endpos + read_len > INTERNAL_PIPE_BUF_SIZE ) {
625
625
// Only read until the end of the ring buffer
626
- to_read = PIPE_BUF - pb -> endpos ;
626
+ to_read = INTERNAL_PIPE_BUF_SIZE - pb -> endpos ;
627
627
}
628
628
629
629
// Read from the socket into the buffer
@@ -645,7 +645,7 @@ void pipebuf_out_to_internal_buffer(pipebuf_t* pb, int read_len) {
645
645
pb -> endpos += to_read ;
646
646
647
647
// If the end position marker is at the buffer end
648
- if (pb -> endpos == PIPE_BUF ) {
648
+ if (pb -> endpos == INTERNAL_PIPE_BUF_SIZE ) {
649
649
// Set it at the start of the buffer for the next read
650
650
pb -> endpos = 0 ;
651
651
}
@@ -855,12 +855,12 @@ void handle_socket_readable() {
855
855
856
856
case CMD_WRITE_CONTROL :
857
857
debug ("CMD: Write to CTRL buf of process with id %d" , id );
858
- pipebuf_out_to_internal_buffer (& p -> ctrl , header [3 ]);
858
+ pipebuf_out_to_internal_buffer (& p -> ctrl , header [3 ] | ( header [ 2 ] << 8 ) );
859
859
break ;
860
860
861
861
case CMD_WRITE_STDIN :
862
862
debug ("CMD: Write to STDIN buf of process with id %d" , id );
863
- pipebuf_out_to_internal_buffer (& p -> stdin , header [3 ]);
863
+ pipebuf_out_to_internal_buffer (& p -> stdin , header [3 ] | ( header [ 2 ] << 8 ) );
864
864
break ;
865
865
866
866
case CMD_ACK_STDOUT :
0 commit comments