@@ -298,6 +298,7 @@ IdentifySystem(void)
298
298
char xpos [MAXFNAMELEN ];
299
299
XLogRecPtr logptr ;
300
300
char * dbname = NULL ;
301
+ Size len ;
301
302
302
303
/*
303
304
* Reply with a result set with one row, four columns. First col is system
@@ -379,21 +380,32 @@ IdentifySystem(void)
379
380
/* Send a DataRow message */
380
381
pq_beginmessage (& buf ,'D' );
381
382
pq_sendint (& buf ,4 ,2 );/* # of columns */
382
- pq_sendint (& buf ,strlen (sysid ),4 );/* col1 len */
383
- pq_sendbytes (& buf , (char * )& sysid ,strlen (sysid ));
384
- pq_sendint (& buf ,strlen (tli ),4 );/* col2 len */
385
- pq_sendbytes (& buf , (char * )tli ,strlen (tli ));
386
- pq_sendint (& buf ,strlen (xpos ),4 );/* col3 len */
387
- pq_sendbytes (& buf , (char * )xpos ,strlen (xpos ));
388
- /* send NULL if not connected to a database */
383
+
384
+ /* column 1: system identifier */
385
+ len = strlen (sysid );
386
+ pq_sendint (& buf ,len ,4 );
387
+ pq_sendbytes (& buf , (char * )& sysid ,len );
388
+
389
+ /* column 2: timeline */
390
+ len = strlen (tli );
391
+ pq_sendint (& buf ,len ,4 );
392
+ pq_sendbytes (& buf , (char * )tli ,len );
393
+
394
+ /* column 3: xlog position */
395
+ len = strlen (xpos );
396
+ pq_sendint (& buf ,len ,4 );
397
+ pq_sendbytes (& buf , (char * )xpos ,len );
398
+
399
+ /* column 4: database name, or NULL if none */
389
400
if (dbname )
390
401
{
391
- pq_sendint (& buf ,strlen (dbname ),4 );/* col4 len */
392
- pq_sendbytes (& buf , (char * )dbname ,strlen (dbname ));
402
+ len = strlen (dbname );
403
+ pq_sendint (& buf ,len ,4 );
404
+ pq_sendbytes (& buf , (char * )dbname ,len );
393
405
}
394
406
else
395
407
{
396
- pq_sendint (& buf ,-1 ,4 );/* col4 len, NULL */
408
+ pq_sendint (& buf ,-1 ,4 );
397
409
}
398
410
399
411
pq_endmessage (& buf );
@@ -412,6 +424,7 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
412
424
int fd ;
413
425
off_t histfilelen ;
414
426
off_t bytesleft ;
427
+ Size len ;
415
428
416
429
/*
417
430
* Reply with a result set with one row, and two columns. The first col is
@@ -447,8 +460,9 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
447
460
/* Send a DataRow message */
448
461
pq_beginmessage (& buf ,'D' );
449
462
pq_sendint (& buf ,2 ,2 );/* # of columns */
450
- pq_sendint (& buf ,strlen (histfname ),4 );/* col1 len */
451
- pq_sendbytes (& buf ,histfname ,strlen (histfname ));
463
+ len = strlen (histfname );
464
+ pq_sendint (& buf ,len ,4 );/* col1 len */
465
+ pq_sendbytes (& buf ,histfname ,len );
452
466
453
467
fd = OpenTransientFile (path ,O_RDONLY |PG_BINARY ,0666 );
454
468
if (fd < 0 )
@@ -674,6 +688,7 @@ StartReplication(StartReplicationCmd *cmd)
674
688
{
675
689
char tli_str [11 ];
676
690
char startpos_str [8 + 1 + 8 + 1 ];
691
+ Size len ;
677
692
678
693
snprintf (tli_str ,sizeof (tli_str ),"%u" ,sendTimeLineNextTLI );
679
694
snprintf (startpos_str ,sizeof (startpos_str ),"%X/%X" ,
@@ -710,11 +725,13 @@ StartReplication(StartReplicationCmd *cmd)
710
725
pq_beginmessage (& buf ,'D' );
711
726
pq_sendint (& buf ,2 ,2 );/* number of columns */
712
727
713
- pq_sendint (& buf ,strlen (tli_str ),4 );/* length */
714
- pq_sendbytes (& buf ,tli_str ,strlen (tli_str ));
728
+ len = strlen (tli_str );
729
+ pq_sendint (& buf ,len ,4 );/* length */
730
+ pq_sendbytes (& buf ,tli_str ,len );
715
731
716
- pq_sendint (& buf ,strlen (startpos_str ),4 );/* length */
717
- pq_sendbytes (& buf ,startpos_str ,strlen (startpos_str ));
732
+ len = strlen (startpos_str );
733
+ pq_sendint (& buf ,len ,4 );/* length */
734
+ pq_sendbytes (& buf ,startpos_str ,len );
718
735
719
736
pq_endmessage (& buf );
720
737
}
@@ -762,10 +779,10 @@ logical_read_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr, int req
762
779
static void
763
780
CreateReplicationSlot (CreateReplicationSlotCmd * cmd )
764
781
{
765
- const char * slot_name ;
766
782
const char * snapshot_name = NULL ;
767
783
char xpos [MAXFNAMELEN ];
768
784
StringInfoData buf ;
785
+ Size len ;
769
786
770
787
Assert (!MyReplicationSlot );
771
788
@@ -790,14 +807,11 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
790
807
791
808
initStringInfo (& output_message );
792
809
793
- slot_name = NameStr (MyReplicationSlot -> data .name );
794
-
795
810
if (cmd -> kind == REPLICATION_KIND_LOGICAL )
796
811
{
797
812
LogicalDecodingContext * ctx ;
798
813
799
- ctx = CreateInitDecodingContext (
800
- cmd -> plugin ,NIL ,
814
+ ctx = CreateInitDecodingContext (cmd -> plugin ,NIL ,
801
815
logical_read_xlog_page ,
802
816
WalSndPrepareWrite ,WalSndWriteData );
803
817
@@ -825,7 +839,6 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
825
839
ReplicationSlotPersist ();
826
840
}
827
841
828
- slot_name = NameStr (MyReplicationSlot -> data .name );
829
842
snprintf (xpos ,sizeof (xpos ),"%X/%X" ,
830
843
(uint32 ) (MyReplicationSlot -> data .confirmed_flush >>32 ),
831
844
(uint32 )MyReplicationSlot -> data .confirmed_flush );
@@ -876,30 +889,34 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
876
889
pq_sendint (& buf ,4 ,2 );/* # of columns */
877
890
878
891
/* slot_name */
879
- pq_sendint (& buf ,strlen (slot_name ),4 );/* col1 len */
880
- pq_sendbytes (& buf ,slot_name ,strlen (slot_name ));
892
+ len = strlen (NameStr (MyReplicationSlot -> data .name ));
893
+ pq_sendint (& buf ,len ,4 );/* col1 len */
894
+ pq_sendbytes (& buf ,NameStr (MyReplicationSlot -> data .name ),len );
881
895
882
896
/* consistent wal location */
883
- pq_sendint (& buf ,strlen (xpos ),4 );/* col2 len */
884
- pq_sendbytes (& buf ,xpos ,strlen (xpos ));
897
+ len = strlen (xpos );
898
+ pq_sendint (& buf ,len ,4 );
899
+ pq_sendbytes (& buf ,xpos ,len );
885
900
886
- /* snapshot name */
901
+ /* snapshot name, or NULL if none */
887
902
if (snapshot_name != NULL )
888
903
{
889
- pq_sendint (& buf ,strlen (snapshot_name ),4 );/* col3 len */
890
- pq_sendbytes (& buf ,snapshot_name ,strlen (snapshot_name ));
904
+ len = strlen (snapshot_name );
905
+ pq_sendint (& buf ,len ,4 );
906
+ pq_sendbytes (& buf ,snapshot_name ,len );
891
907
}
892
908
else
893
- pq_sendint (& buf ,-1 ,4 );/* col3 len, NULL */
909
+ pq_sendint (& buf ,-1 ,4 );
894
910
895
- /* plugin */
911
+ /* plugin, or NULL if none */
896
912
if (cmd -> plugin != NULL )
897
913
{
898
- pq_sendint (& buf ,strlen (cmd -> plugin ),4 );/* col4 len */
899
- pq_sendbytes (& buf ,cmd -> plugin ,strlen (cmd -> plugin ));
914
+ len = strlen (cmd -> plugin );
915
+ pq_sendint (& buf ,len ,4 );
916
+ pq_sendbytes (& buf ,cmd -> plugin ,len );
900
917
}
901
918
else
902
- pq_sendint (& buf ,-1 ,4 );/* col4 len, NULL */
919
+ pq_sendint (& buf ,-1 ,4 );
903
920
904
921
pq_endmessage (& buf );
905
922