forked from swoole/swoole-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swoole.c
2998 lines (2629 loc) · 77.8 KB
/
swoole.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
+----------------------------------------------------------------------+
| Swoole |
+----------------------------------------------------------------------+
| This source file is subject to version 2.0 of the Apache license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.apache.org/licenses/LICENSE-2.0.html |
| If you did not receive a copy of the Apache2.0 license and are unable|
| to obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Tianfeng Han <mikan.tenny@gmail.com> |
+----------------------------------------------------------------------+
*/
/* $Id: swoole.c 2013-12-24 10:31:55Z tianfeng $ */
#include "php_swoole.h"
#include <ext/standard/info.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <ifaddrs.h>
zval *php_sw_callback[PHP_SERVER_CALLBACK_NUM];
HashTable php_sw_event_callback;
HashTable php_sw_timer_callback;
HashTable php_sw_client_callback;
HashTable php_sw_aio_callback;
#ifdef ZTS
void ***sw_thread_ctx;
#endif
static swEventData *sw_current_task;
static int php_swoole_task_id;
static int php_swoole_udp_from_id;
static int php_swoole_unix_dgram_fd;
extern sapi_module_struct sapi_module;
ZEND_DECLARE_MODULE_GLOBALS(swoole)
// arginfo server
// *_oo : for object style
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_create, 0, 0, 2)
ZEND_ARG_INFO(0, serv_host)
ZEND_ARG_INFO(0, serv_port)
ZEND_ARG_INFO(0, serv_mode)
ZEND_ARG_INFO(0, sock_type)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_set, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_ARG_INFO(0, zset)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_set_oo, 0, 0, 1)
ZEND_ARG_INFO(0, zset)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_start, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_END_ARG_INFO()
//for object style
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_start_oo, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_send, 0, 0, 3)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_ARG_INFO(0, conn_fd)
ZEND_ARG_INFO(0, send_data)
ZEND_ARG_INFO(0, from_id)
ZEND_END_ARG_INFO()
//for object style
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_send_oo, 0, 0, 2)
ZEND_ARG_INFO(0, conn_fd)
ZEND_ARG_INFO(0, send_data)
ZEND_ARG_INFO(0, from_id)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_sendfile, 0, 0, 3)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_ARG_INFO(0, conn_fd)
ZEND_ARG_INFO(0, filename)
ZEND_END_ARG_INFO()
//for object style
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_sendfile_oo, 0, 0, 2)
ZEND_ARG_INFO(0, conn_fd)
ZEND_ARG_INFO(0, filename)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_close, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_ARG_INFO(0, fd)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_close_oo, 0, 0, 1)
ZEND_ARG_INFO(0, fd)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_handler, 0, 0, 3)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_ARG_INFO(0, ha_name)
ZEND_ARG_INFO(0, cb)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_handler_oo, 0, 0, 2)
ZEND_ARG_INFO(0, ha_name)
ZEND_ARG_INFO(0, cb)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_on, 0, 0, 3)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_ARG_INFO(0, ha_name)
ZEND_ARG_INFO(0, cb)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_on_oo, 0, 0, 2)
ZEND_ARG_INFO(0, ha_name)
ZEND_ARG_INFO(0, cb)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_addlisten, 0, 0, 4)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_ARG_INFO(0, host)
ZEND_ARG_INFO(0, port)
ZEND_ARG_INFO(0, sock_type)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_addlisten_oo, 0, 0, 3)
ZEND_ARG_INFO(0, host)
ZEND_ARG_INFO(0, port)
ZEND_ARG_INFO(0, sock_type)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_addtimer, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_ARG_INFO(0, interval)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_addtimer_oo, 0, 0, 1)
ZEND_ARG_INFO(0, interval)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_deltimer, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_ARG_INFO(0, interval)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_deltimer_oo, 0, 0, 1)
ZEND_ARG_INFO(0, interval)
ZEND_END_ARG_INFO()
//function style
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_task, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, worker_id)
ZEND_END_ARG_INFO()
//object style
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_task_oo, 0, 0, 2)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, worker_id)
ZEND_END_ARG_INFO()
//function style
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_taskwait, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, timeout)
ZEND_ARG_INFO(0, worker_id)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_taskwait_oo, 0, 0, 1)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, timeout)
ZEND_ARG_INFO(0, worker_id)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_finish, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_ARG_INFO(0, data)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_finish_oo, 0, 0, 1)
ZEND_ARG_INFO(0, data)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_reload, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_reload_oo, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_shutdown, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_shutdown_oo, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_heartbeat, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_ARG_INFO(0, from_id)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_heartbeat_oo, 0, 0, 1)
ZEND_ARG_INFO(0, from_id)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_connection_info, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_ARG_INFO(0, fd)
ZEND_ARG_INFO(0, from_id)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_connection_info_oo, 0, 0, 2)
ZEND_ARG_INFO(0, fd)
ZEND_ARG_INFO(0, from_id)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_connection_list, 0, 0, 3)
ZEND_ARG_OBJ_INFO(0, zobject, swoole_server, 0)
ZEND_ARG_INFO(0, start_fd)
ZEND_ARG_INFO(0, find_count)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_connection_list_oo, 0, 0, 2)
ZEND_ARG_INFO(0, start_fd)
ZEND_ARG_INFO(0, find_count)
ZEND_END_ARG_INFO()
//arginfo event
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_event_add, 0, 0, 2)
ZEND_ARG_INFO(0, fd)
ZEND_ARG_INFO(0, cb)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_event_del, 0, 0, 1)
ZEND_ARG_INFO(0, fd)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_event_exit, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_event_wait, 0, 0, 0)
ZEND_END_ARG_INFO()
//arginfo timer
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_timer_add, 0, 0, 2)
ZEND_ARG_INFO(0, interval)
ZEND_ARG_INFO(0, cb)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_timer_del, 0, 0, 1)
ZEND_ARG_INFO(0, interval)
ZEND_END_ARG_INFO()
//arginfo end
static int php_swoole_onReceive(swFactory *, swEventData *);
static void php_swoole_onStart(swServer *);
static void php_swoole_onShutdown(swServer *);
static void php_swoole_onConnect(swServer *, int fd, int from_id);
static void php_swoole_onClose(swServer *, int fd, int from_id);
static void php_swoole_onTimer(swServer *serv, int interval);
static void php_swoole_onWorkerStart(swServer *, int worker_id);
static void php_swoole_onWorkerStop(swServer *, int worker_id);
static int php_swoole_onTask(swServer *, swEventData *task);
static int php_swoole_onFinish(swServer *, swEventData *task);
static void php_swoole_onWorkerError(swServer *serv, int worker_id, pid_t worker_pid, int exit_code);
static void swoole_destory_server(zend_rsrc_list_entry *rsrc TSRMLS_DC);
static void swoole_destory_client(zend_rsrc_list_entry *rsrc TSRMLS_DC);
static int php_swoole_task_finish(swServer *serv, char *data, int data_len TSRMLS_DC);
static int php_swoole_set_callback(int key, zval *cb TSRMLS_DC);
#define SWOOLE_GET_SERVER(zobject, serv) zval **zserv;\
if (zend_hash_find(Z_OBJPROP_P(zobject), ZEND_STRS("_server"), (void **) &zserv) == FAILURE){ \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not have swoole server");\
RETURN_FALSE;}\
ZEND_FETCH_RESOURCE(serv, swServer *, zserv, -1, SW_RES_SERVER_NAME, le_swoole_server);
#ifdef SW_ASYNC_MYSQL
#include "ext/mysqlnd/mysqlnd.h"
#include "ext/mysqli/mysqli_mysqlnd.h"
#include "ext/mysqli/php_mysqli_structs.h"
#endif
#include "zend_exceptions.h"
const zend_function_entry swoole_functions[] =
{
PHP_FE(swoole_version, NULL)
PHP_FE(swoole_cpu_num, NULL)
/*------swoole_server-----*/
PHP_FE(swoole_server_create, arginfo_swoole_server_create)
PHP_FE(swoole_server_set, arginfo_swoole_server_set)
PHP_FE(swoole_server_start, arginfo_swoole_server_start)
PHP_FE(swoole_server_send, arginfo_swoole_server_send)
PHP_FE(swoole_server_sendfile, arginfo_swoole_server_sendfile)
PHP_FE(swoole_server_close, arginfo_swoole_server_close)
PHP_FE(swoole_server_handler, arginfo_swoole_server_handler)
PHP_FE(swoole_server_on, arginfo_swoole_server_on)
PHP_FE(swoole_server_addlisten, arginfo_swoole_server_addlisten)
PHP_FE(swoole_server_addtimer, arginfo_swoole_server_addtimer)
PHP_FE(swoole_server_deltimer, arginfo_swoole_server_deltimer)
PHP_FE(swoole_server_task, arginfo_swoole_server_task)
PHP_FE(swoole_server_taskwait, arginfo_swoole_server_taskwait)
PHP_FE(swoole_server_finish, arginfo_swoole_server_finish)
PHP_FE(swoole_server_reload, arginfo_swoole_server_reload)
PHP_FE(swoole_server_shutdown, arginfo_swoole_server_shutdown)
PHP_FE(swoole_server_heartbeat, arginfo_swoole_server_heartbeat)
PHP_FE(swoole_connection_info, arginfo_swoole_connection_info)
PHP_FE(swoole_connection_list, arginfo_swoole_connection_list)
/*------swoole_event-----*/
PHP_FE(swoole_event_add, arginfo_swoole_event_add)
PHP_FE(swoole_event_set, NULL)
PHP_FE(swoole_event_del, arginfo_swoole_event_del)
PHP_FE(swoole_event_exit, arginfo_swoole_event_exit)
PHP_FE(swoole_event_wait, arginfo_swoole_event_wait)
/*------swoole_timer-----*/
PHP_FE(swoole_timer_add, arginfo_swoole_timer_add)
PHP_FE(swoole_timer_del, arginfo_swoole_timer_del)
/*------swoole_async_io------*/
PHP_FE(swoole_async_read, NULL)
PHP_FE(swoole_async_write, NULL)
PHP_FE(swoole_async_readfile, NULL)
PHP_FE(swoole_async_writefile, NULL)
PHP_FE(swoole_async_dns_lookup, NULL)
/*------other-----*/
PHP_FE(swoole_client_select, NULL)
PHP_FE(swoole_set_process_name, NULL)
PHP_FE(swoole_get_local_ip, NULL)
PHP_FE(swoole_strerror, NULL)
PHP_FE(swoole_errno, NULL)
#ifdef SW_ASYNC_MYSQL
PHP_FE(swoole_get_mysqli_sock, NULL)
#endif
PHP_FE_END /* Must be the last line in swoole_functions[] */
};
static zend_function_entry swoole_server_methods[] = {
PHP_FALIAS(__construct, swoole_server_create, arginfo_swoole_server_create)
PHP_FALIAS(set, swoole_server_set, arginfo_swoole_server_set_oo)
PHP_FALIAS(start, swoole_server_start, arginfo_swoole_server_start_oo)
PHP_FALIAS(send, swoole_server_send, arginfo_swoole_server_send_oo)
PHP_FALIAS(sendfile, swoole_server_sendfile, arginfo_swoole_server_sendfile_oo)
PHP_FALIAS(close, swoole_server_close, arginfo_swoole_server_close_oo)
PHP_FALIAS(task, swoole_server_task, arginfo_swoole_server_task_oo)
PHP_FALIAS(taskwait, swoole_server_taskwait, arginfo_swoole_server_taskwait_oo)
PHP_FALIAS(finish, swoole_server_finish, arginfo_swoole_server_finish_oo)
PHP_FALIAS(addlistener, swoole_server_addlisten, arginfo_swoole_server_addlisten_oo)
PHP_FALIAS(addtimer, swoole_server_addtimer, arginfo_swoole_server_addtimer_oo)
PHP_FALIAS(deltimer, swoole_server_deltimer, arginfo_swoole_server_deltimer_oo)
PHP_FALIAS(reload, swoole_server_reload, arginfo_swoole_server_reload_oo)
PHP_FALIAS(shutdown, swoole_server_shutdown, arginfo_swoole_server_shutdown_oo)
PHP_FALIAS(hbcheck, swoole_server_heartbeat, arginfo_swoole_server_heartbeat_oo)
PHP_FALIAS(heartbeat, swoole_server_heartbeat, arginfo_swoole_server_heartbeat_oo)
PHP_FALIAS(handler, swoole_server_handler, arginfo_swoole_server_handler_oo)
PHP_FALIAS(on, swoole_server_on, arginfo_swoole_server_on_oo)
PHP_FALIAS(connection_info, swoole_connection_info, arginfo_swoole_connection_info_oo)
PHP_FALIAS(connection_list, swoole_connection_list, arginfo_swoole_connection_list_oo)
{NULL, NULL, NULL}
};
const zend_function_entry swoole_client_methods[] =
{
PHP_ME(swoole_client, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(swoole_client, connect, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_client, recv, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_client, send, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_client, close, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_client, on, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
const zend_function_entry swoole_process_methods[] =
{
PHP_ME(swoole_process, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(swoole_process, wait, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(swoole_process, kill, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(swoole_process, start, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_process, write, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_process, read, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_process, exit, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_process, exec, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
const zend_function_entry swoole_buffer_methods[] =
{
PHP_ME(swoole_buffer, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(swoole_buffer, substr, NULL, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_buffer, read, substr, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_buffer, write, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_buffer, append, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_buffer, expand, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_buffer, clear, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
const zend_function_entry swoole_table_methods[] =
{
PHP_ME(swoole_table, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(swoole_table, column, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, create, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, add, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, get, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, lock, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, unlock, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
const zend_function_entry swoole_lock_methods[] =
{
PHP_ME(swoole_lock, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(swoole_lock, lock, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_lock, trylock, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_lock, lock_read, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_lock, trylock_read, NULL, ZEND_ACC_PUBLIC)
PHP_ME(swoole_lock, unlock, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
int le_swoole_server;
int le_swoole_client;
int le_swoole_lock;
int le_swoole_process;
int le_swoole_table;
int le_swoole_buffer;
zend_class_entry swoole_lock_ce;
zend_class_entry *swoole_lock_class_entry_ptr;
zend_class_entry swoole_client_ce;
zend_class_entry *swoole_client_class_entry_ptr;
zend_class_entry swoole_process_ce;
zend_class_entry *swoole_process_class_entry_ptr;
zend_class_entry swoole_server_ce;
zend_class_entry *swoole_server_class_entry_ptr;
zend_class_entry swoole_table_ce;
zend_class_entry *swoole_table_class_entry_ptr;
zend_class_entry swoole_buffer_ce;
zend_class_entry *swoole_buffer_class_entry_ptr;
zend_module_entry swoole_module_entry =
{
#if ZEND_MODULE_API_NO >= 20050922
STANDARD_MODULE_HEADER_EX,
NULL,
NULL,
#else
STANDARD_MODULE_HEADER,
#endif
"swoole",
swoole_functions,
PHP_MINIT(swoole),
PHP_MSHUTDOWN(swoole),
PHP_RINIT(swoole), //RINIT
PHP_RSHUTDOWN(swoole), //RSHUTDOWN
PHP_MINFO(swoole),
PHP_SWOOLE_VERSION,
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_SWOOLE
ZEND_GET_MODULE(swoole)
#endif
/* {{{ PHP_INI
*/
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("swoole.task_worker_num", "0", PHP_INI_ALL, OnUpdateLong, task_worker_num, zend_swoole_globals, swoole_globals)
STD_PHP_INI_ENTRY("swoole.task_ipc_mode", "0", PHP_INI_ALL, OnUpdateString, task_ipc_mode, zend_swoole_globals, swoole_globals)
STD_PHP_INI_ENTRY("swoole.task_auto_start", "0", PHP_INI_ALL, OnUpdateString, task_auto_start, zend_swoole_globals, swoole_globals)
STD_PHP_INI_ENTRY("swoole.message_queue_key", "0", PHP_INI_ALL, OnUpdateString, message_queue_key, zend_swoole_globals, swoole_globals)
/**
* Unix socket buffer size
*/
STD_PHP_INI_ENTRY("swoole.unixsock_buffer_size", "8388608", PHP_INI_ALL, OnUpdateLong, unixsock_buffer_size, zend_swoole_globals, swoole_globals)
PHP_INI_END()
static void php_swoole_init_globals(zend_swoole_globals *swoole_globals)
{
swoole_globals->task_worker_num = 0;
swoole_globals->task_ipc_mode = 0;
swoole_globals->unixsock_buffer_size = SW_UNSOCK_BUFSIZE;
}
/* {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(swoole)
{
ZEND_INIT_MODULE_GLOBALS(swoole, php_swoole_init_globals, NULL);
REGISTER_INI_ENTRIES();
le_swoole_server = zend_register_list_destructors_ex(swoole_destory_server, NULL, SW_RES_SERVER_NAME, module_number);
le_swoole_client = zend_register_list_destructors_ex(swoole_destory_client, NULL, SW_RES_CLIENT_NAME, module_number);
le_swoole_lock = zend_register_list_destructors_ex(swoole_destory_lock, NULL, SW_RES_LOCK_NAME, module_number);
le_swoole_process = zend_register_list_destructors_ex(swoole_destory_process, NULL, SW_RES_PROCESS_NAME, module_number);
le_swoole_buffer = zend_register_list_destructors_ex(swoole_destory_buffer, NULL, SW_RES_BUFFER_NAME, module_number);
le_swoole_table = zend_register_list_destructors_ex(swoole_destory_table, NULL, SW_RES_TABLE_NAME, module_number);
/**
* mode type
*/
REGISTER_LONG_CONSTANT("SWOOLE_BASE", SW_MODE_SINGLE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_THREAD", SW_MODE_THREAD, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_PROCESS", SW_MODE_PROCESS, CONST_CS | CONST_PERSISTENT);
/**
* ipc mode
*/
REGISTER_LONG_CONSTANT("SWOOLE_IPC_UNSOCK", SW_IPC_UNSOCK, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_IPC_MSGQUEUE", SW_IPC_MSGQUEUE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_IPC_CHANNEL", SW_IPC_CHANNEL, CONST_CS | CONST_PERSISTENT);
/**
* socket type
*/
REGISTER_LONG_CONSTANT("SWOOLE_SOCK_TCP", SW_SOCK_TCP, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_SOCK_TCP6", SW_SOCK_TCP6, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_SOCK_UDP", SW_SOCK_UDP, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_SOCK_UDP6", SW_SOCK_UDP6, CONST_CS | CONST_PERSISTENT);
/**
* simple api
*/
REGISTER_LONG_CONSTANT("SWOOLE_TCP", SW_SOCK_TCP, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_TCP6", SW_SOCK_TCP6, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_UDP", SW_SOCK_UDP, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_UDP6", SW_SOCK_UDP6, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_UNIX_DGRAM", SW_SOCK_UNIX_DGRAM, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_UNIX_STREAM", SW_SOCK_UNIX_STREAM, CONST_CS | CONST_PERSISTENT);
/**
* Lock type
*/
REGISTER_LONG_CONSTANT("SWOOLE_RWLOCK", SW_RWLOCK, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_FILELOCK", SW_FILELOCK, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_MUTEX", SW_MUTEX, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_SEM", SW_SEM, CONST_CS | CONST_PERSISTENT);
#ifdef HAVE_SPINLOCK
REGISTER_LONG_CONSTANT("SWOOLE_SPINLOCK", SW_SPINLOCK, CONST_CS | CONST_PERSISTENT);
#endif
/**
* simple api
*/
REGISTER_LONG_CONSTANT("SWOOLE_SOCK_SYNC", SW_SOCK_SYNC, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_SOCK_ASYNC", SW_SOCK_ASYNC, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_SYNC", SW_FLAG_SYNC, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_ASYNC", SW_FLAG_ASYNC, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_KEEP", SW_FLAG_KEEP, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_SSL", SW_SOCK_SSL, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_EVENT_READ", SW_EVENT_READ, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SWOOLE_EVENT_WRITE", SW_EVENT_WRITE, CONST_CS | CONST_PERSISTENT);
REGISTER_STRINGL_CONSTANT("SWOOLE_VERSION", PHP_SWOOLE_VERSION, sizeof(PHP_SWOOLE_VERSION) - 1, CONST_CS | CONST_PERSISTENT);
INIT_CLASS_ENTRY(swoole_client_ce, "swoole_client", swoole_client_methods);
swoole_client_class_entry_ptr = zend_register_internal_class(&swoole_client_ce TSRMLS_CC);
zend_declare_property_long(swoole_client_class_entry_ptr, SW_STRL("errCode")-1, 0, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_long(swoole_client_class_entry_ptr, SW_STRL("sock")-1, 0, ZEND_ACC_PUBLIC TSRMLS_CC);
INIT_CLASS_ENTRY(swoole_server_ce, "swoole_server", swoole_server_methods);
swoole_server_class_entry_ptr = zend_register_internal_class(&swoole_server_ce TSRMLS_CC);
INIT_CLASS_ENTRY(swoole_lock_ce, "swoole_lock", swoole_lock_methods);
swoole_lock_class_entry_ptr = zend_register_internal_class(&swoole_lock_ce TSRMLS_CC);
INIT_CLASS_ENTRY(swoole_process_ce, "swoole_process", swoole_process_methods);
swoole_process_class_entry_ptr = zend_register_internal_class(&swoole_process_ce TSRMLS_CC);
INIT_CLASS_ENTRY(swoole_buffer_ce, "swoole_buffer", swoole_buffer_methods);
swoole_buffer_class_entry_ptr = zend_register_internal_class(&swoole_buffer_ce TSRMLS_CC);
INIT_CLASS_ENTRY(swoole_table_ce, "swoole_table", swoole_table_methods);
swoole_table_class_entry_ptr = zend_register_internal_class(&swoole_table_ce TSRMLS_CC);
zend_hash_init(&php_sw_long_connections, 16, NULL, ZVAL_PTR_DTOR, 1);
swoole_table_init(TSRMLS_CC);
//swoole init
swoole_init();
if (SWOOLE_G(unixsock_buffer_size) > 0)
{
SwooleG.unixsock_buffer_size = SWOOLE_G(unixsock_buffer_size);
}
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
PHP_MSHUTDOWN_FUNCTION(swoole)
{
swoole_clean();
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(swoole)
{
php_info_print_table_start();
php_info_print_table_header(2, "swoole support", "enabled");
php_info_print_table_row(2, "Version", PHP_SWOOLE_VERSION);
php_info_print_table_row(2, "Author", "tianfeng.han[email: mikan.tenny@gmail.com]");
#ifdef HAVE_EPOLL
php_info_print_table_row(2, "epoll", "enabled");
#endif
#ifdef HAVE_EVENTFD
php_info_print_table_row(2, "event_fd", "enabled");
#endif
#ifdef HAVE_KQUEUE
php_info_print_table_row(2, "kqueue", "enabled");
#endif
#ifdef HAVE_TIMERFD
php_info_print_table_row(2, "timerfd", "enabled");
#endif
#ifdef SW_USE_ACCEPT4
php_info_print_table_row(2, "accept4", "enabled");
#endif
#ifdef HAVE_CPU_AFFINITY
php_info_print_table_row(2, "cpu affinity", "enabled");
#endif
#ifdef HAVE_SPINLOCK
php_info_print_table_row(2, "spinlock", "enabled");
#endif
#ifdef SW_ASYNC_MYSQL
php_info_print_table_row(2, "async mysql", "enabled");
#endif
#ifdef SW_SOCKETS
php_info_print_table_row(2, "sockets", "enabled");
#endif
#ifdef SW_USE_OPENSSL
php_info_print_table_row(2, "openssl", "enabled");
#endif
#ifdef SW_USE_RINGBUFFER
php_info_print_table_row(2, "ringbuffer", "enabled");
#endif
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
/* }}} */
PHP_RINIT_FUNCTION(swoole)
{
//swoole_event_add
zend_hash_init(&php_sw_event_callback, 16, NULL, ZVAL_PTR_DTOR, 0);
//swoole_client::on
zend_hash_init(&php_sw_client_callback, 16, NULL, ZVAL_PTR_DTOR, 0);
//swoole_timer_add
zend_hash_init(&php_sw_timer_callback, 16, NULL, ZVAL_PTR_DTOR, 0);
//swoole_aio
zend_hash_init(&php_sw_aio_callback, 16, NULL, ZVAL_PTR_DTOR, 0);
//running
SwooleG.running = 1;
return SUCCESS;
}
PHP_RSHUTDOWN_FUNCTION(swoole)
{
zend_hash_destroy(&php_sw_event_callback);
zend_hash_destroy(&php_sw_client_callback);
zend_hash_destroy(&php_sw_timer_callback);
zend_hash_destroy(&php_sw_aio_callback);
int i;
for(i=0; i<PHP_SERVER_CALLBACK_NUM; i++)
{
if(php_sw_callback[i] != NULL)
{
zval_dtor(php_sw_callback[i]);
efree(php_sw_callback[i]);
}
}
php_sw_reactor_wait_onexit = 0;
return SUCCESS;
}
static void swoole_destory_server(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
SwooleG.running = 0;
swServer *serv = (swServer *) rsrc->ptr;
if (serv != NULL)
{
swServer_shutdown(serv);
}
}
static void swoole_destory_client(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
swClient *cli = (swClient *) rsrc->ptr;
if (cli->keep == 0)
{
if (cli->connection.fd != 0)
{
cli->close(cli);
}
efree(cli);
}
}
PHP_FUNCTION(swoole_version)
{
char swoole_version[32] = {0};
snprintf(swoole_version, sizeof(PHP_SWOOLE_VERSION), "%s", PHP_SWOOLE_VERSION);
RETURN_STRING(swoole_version, 1);
}
PHP_FUNCTION(swoole_cpu_num)
{
long cpu_num = 1;
cpu_num = sysconf(_SC_NPROCESSORS_CONF);
if(cpu_num < 1)
{
cpu_num = 1;
}
RETURN_LONG(cpu_num);
}
#ifdef SW_ASYNC_MYSQL
PHP_FUNCTION(swoole_get_mysqli_sock)
{
MY_MYSQL *mysql;
zval *mysql_link;
int sock;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &mysql_link) == FAILURE)
{
return;
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
php_stream *stream;
#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 4
stream = mysql->mysql->data->net->data->m.get_stream(mysql->mysql->data->net TSRMLS_CC);
#else
stream = mysql->mysql->data->net->stream;
#endif
if (SUCCESS != php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void* )&sock, 1)
&& sock >= 0)
{
RETURN_FALSE;
}
else
{
RETURN_LONG(sock);
}
}
#endif
PHP_FUNCTION(swoole_server_create)
{
int host_len = 0;
char *serv_host;
long sock_type = SW_SOCK_TCP;
long serv_port;
long serv_mode = SW_MODE_PROCESS;
//only cli env
if (strcasecmp("cli", sapi_module.name) != 0)
{
php_error_docref(NULL TSRMLS_CC, E_ERROR, "swoole_server must run at php_cli environment.");
RETURN_FALSE;
}
if (SwooleGS->start > 0)
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Server is already running. Unable to create swoole_server.");
RETURN_FALSE;
}
swServer *serv = sw_malloc(sizeof(swServer));
swServer_init(serv);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ll", &serv_host, &host_len, &serv_port, &serv_mode, &sock_type) == FAILURE)
{
return;
}
if (serv_mode == SW_MODE_THREAD || serv_mode == SW_MODE_BASE)
{
serv_mode = SW_MODE_SINGLE;
php_error_docref(NULL TSRMLS_CC, E_WARNING, "PHP can not running at multi-threading. Reset mode to SWOOLE_MODE_BASE");
}
serv->factory_mode = serv_mode;
swTrace("Create swoole_server host=%s, port=%ld, mode=%d, type=%d", serv_host, serv_port, serv->factory_mode, sock_type);
#ifdef ZTS
if(sw_thread_ctx == NULL)
{
TSRMLS_SET_CTX(sw_thread_ctx);
}
#endif
bzero(php_sw_callback, sizeof(zval*) * PHP_SERVER_CALLBACK_NUM);
if (swServer_addListener(serv, sock_type, serv_host, serv_port) < 0)
{
php_error_docref(NULL TSRMLS_CC, E_ERROR, "add listener failed.");
return;
}
if (!getThis())
{
object_init_ex(return_value, swoole_server_class_entry_ptr);
getThis() = return_value;
}
zval *zres;
MAKE_STD_ZVAL(zres);
ZEND_REGISTER_RESOURCE(zres, serv, le_swoole_server);
zend_update_property(swoole_server_class_entry_ptr, getThis(), ZEND_STRL("_server"), zres TSRMLS_CC);
zval_ptr_dtor(&zres);
}
PHP_FUNCTION(swoole_server_set)
{
zval *zset = NULL;
zval *zobject = getThis();
HashTable * vht;
swServer *serv;
zval **v;
double timeout;
if (SwooleGS->start > 0)
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Server is running. Unable to execute swoole_server_set now.");
RETURN_FALSE;
}
if (zobject == NULL)
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Oa", &zobject, swoole_server_class_entry_ptr, &zset) == FAILURE)
{
return;
}
}
else
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &zset) == FAILURE)
{
return;
}
}
SWOOLE_GET_SERVER(zobject, serv);
vht = Z_ARRVAL_P(zset);
//timeout
if (zend_hash_find(vht, ZEND_STRS("timeout"), (void **)&v) == SUCCESS)
{
convert_to_double(*v);
timeout = Z_DVAL_PP(v);
serv->timeout_sec = (int)timeout;
serv->timeout_usec = (int)((timeout*1000*1000) - (serv->timeout_sec*1000*1000));
}
//daemonize
if (zend_hash_find(vht, ZEND_STRS("daemonize"), (void **)&v) == SUCCESS)
{
convert_to_long(*v);
serv->daemonize = (int)Z_LVAL_PP(v);
}
//backlog
if (zend_hash_find(vht, ZEND_STRS("backlog"), (void **)&v) == SUCCESS)
{
serv->backlog = (int)Z_LVAL_PP(v);
}
//poll_thread_num
if (zend_hash_find(vht, ZEND_STRS("reactor_num"), (void **) &v) == SUCCESS
|| zend_hash_find(vht, ZEND_STRS("poll_thread_num"), (void **) &v) == SUCCESS)
{
convert_to_long(*v);
serv->reactor_num = (int) Z_LVAL_PP(v);
}
//writer_num
if (zend_hash_find(vht, ZEND_STRS("writer_num"), (void **)&v) == SUCCESS)
{
convert_to_long(*v);
serv->writer_num = (int)Z_LVAL_PP(v);
}
//worker_num
if (zend_hash_find(vht, ZEND_STRS("worker_num"), (void **)&v) == SUCCESS)
{
convert_to_long(*v);
serv->worker_num = (int)Z_LVAL_PP(v);
}
//task_worker_num
if (zend_hash_find(vht, ZEND_STRS("task_worker_num"), (void **)&v) == SUCCESS)
{
convert_to_long(*v);
SwooleG.task_worker_num = (int)Z_LVAL_PP(v);
}
if (zend_hash_find(vht, ZEND_STRS("task_ipc_mode"), (void **)&v) == SUCCESS)
{
convert_to_long(*v);
SwooleG.task_ipc_mode = (int)Z_LVAL_PP(v);
}
//max_conn
if (zend_hash_find(vht, ZEND_STRS("max_conn"), (void **)&v) == SUCCESS)
{
convert_to_long(*v);
serv->max_conn = (int)Z_LVAL_PP(v);
}
//max_request
if (zend_hash_find(vht, ZEND_STRS("max_request"), (void **)&v) == SUCCESS)
{
convert_to_long(*v);
serv->max_request = (int)Z_LVAL_PP(v);
}
//cpu affinity
if (zend_hash_find(vht, ZEND_STRS("open_cpu_affinity"), (void **)&v) == SUCCESS)
{
convert_to_long(*v);
serv->open_cpu_affinity = (uint8_t)Z_LVAL_PP(v);
}
//tcp_nodelay
if (zend_hash_find(vht, ZEND_STRS("open_tcp_nodelay"), (void **)&v) == SUCCESS)
{
convert_to_long(*v);
serv->open_tcp_nodelay = (uint8_t)Z_LVAL_PP(v);
}
//tcp_defer_accept
if (zend_hash_find(vht, ZEND_STRS("tcp_defer_accept"), (void **)&v) == SUCCESS)
{
convert_to_long(*v);
serv->tcp_defer_accept = (uint8_t)Z_LVAL_PP(v);
}
//socket linger
if (zend_hash_find(vht, ZEND_STRS("tcp_socket_linger"), (void **)&v) == SUCCESS)
{
convert_to_long(*v);
serv->tcp_socket_linger = (uint8_t)Z_LVAL_PP(v);
}
//tcp_keepalive
if (zend_hash_find(vht, ZEND_STRS("open_tcp_keepalive"), (void **)&v) == SUCCESS)
{
serv->open_tcp_keepalive = (uint8_t)Z_LVAL_PP(v);
}
//buffer: check eof
if (zend_hash_find(vht, ZEND_STRS("open_eof_check"), (void **)&v) == SUCCESS)
{
convert_to_long(*v);
serv->open_eof_check = (uint8_t)Z_LVAL_PP(v);
}
//package eof
if (zend_hash_find(vht, ZEND_STRS("package_eof"), (void **) &v) == SUCCESS
|| zend_hash_find(vht, ZEND_STRS("data_eof"), (void **) &v) == SUCCESS)
{
convert_to_string(*v);
serv->package_eof_len = Z_STRLEN_PP(v);
if (serv->package_eof_len > SW_DATA_EOF_MAXLEN)
{
php_error_docref(NULL TSRMLS_CC, E_ERROR, "swoole_server date_eof max length is %d", SW_DATA_EOF_MAXLEN);
RETURN_FALSE;
}
bzero(serv->package_eof, SW_DATA_EOF_MAXLEN);
memcpy(serv->package_eof, Z_STRVAL_PP(v), Z_STRLEN_PP(v));
}
//tcp_keepidle
if (zend_hash_find(vht, ZEND_STRS("tcp_keepidle"), (void **)&v) == SUCCESS)
{
convert_to_long(*v);
serv->tcp_keepidle = (uint16_t)Z_LVAL_PP(v);
}
//tcp_keepinterval
if (zend_hash_find(vht, ZEND_STRS("tcp_keepinterval"), (void **)&v) == SUCCESS)
{
convert_to_long(*v);
serv->tcp_keepinterval = (uint16_t)Z_LVAL_PP(v);
}