@@ -146,7 +146,7 @@ struct Channel
146
146
int curSubPos ; // Point from where you can read future msgs.
147
147
int curMsgReadPos ; // Cur point of reading.
148
148
int totalMsgs ; // Total msgs in channel (readable and not).
149
- struct Message msgs [256 ];
149
+ struct Message msgs [1000 ];
150
150
};
151
151
152
152
@@ -300,7 +300,7 @@ char* Unsub(char buffer[BUFFER_SIZE]) // Unsubscribes client from specified chan
300
300
{
301
301
char * id = GetIdFromBuffer (buffer , 5 , 4 );
302
302
if (ValidID (id ) < 0 ) // Invalid id.
303
- return replace_str ("Invalid channel: xxx. \n" ,"xxx" ,id );
303
+ return replace_str ("Invalid channel: xxx\n" ,"xxx" ,id );
304
304
305
305
int i = GetClientSubIndex (id );
306
306
if (i < 0 ) // Not subscribed to this chan id.
@@ -332,7 +332,7 @@ char* Sub(char buffer[BUFFER_SIZE])
332
332
{
333
333
char * id = GetIdFromBuffer (buffer , 3 , 4 );
334
334
if (ValidID (id ) < 0 ) // Return if invalid id.
335
- return replace_str ("Invalid channel: xxx. \n" ,"xxx" ,id );
335
+ return replace_str ("Invalid channel: xxx\n" ,"xxx" ,id );
336
336
337
337
if (GetClientSubIndex (id ) >= 0 )
338
338
return replace_str ("Already subscribed to channel xxx.\n" ,"xxx" ,id );
@@ -495,9 +495,11 @@ char* Next(char* buffer)
495
495
*/
496
496
char * NextAll ()
497
497
{
498
- if (client .curChanPos == 0 ) // If not return min length, no subs.
498
+ if (client .curChanPos == 0 ) // If not return min length, no subs.
499
+ {
500
+ streaming = 0 ;
499
501
return "Not subscribed to any channels.\n" ;
500
-
502
+ }
501
503
int nextChanID = 99999 ;
502
504
long long nextMsgSentTime = 9999999999999 ;
503
505
@@ -536,6 +538,14 @@ char* NextAll()
536
538
*/
537
539
void LiveStream (int newsockfd , char buffer [BUFFER_SIZE ])
538
540
{
541
+ if (client .curChanPos == 0 ) // If not return min length, no subs.
542
+ {
543
+
544
+ streaming = 0 ;
545
+ WriteClient (newsockfd , "Not subscribed to any channels.\n" );
546
+ return ;
547
+ }
548
+
539
549
streaming = 1 ;
540
550
char * newBuffer = calloc (BUFFER_SIZE , sizeof (char ));
541
551
@@ -544,6 +554,7 @@ void LiveStream(int newsockfd, char buffer[BUFFER_SIZE])
544
554
545
555
while (streaming == 1 )
546
556
{
557
+ printf (")))\n" );
547
558
char * msg = calloc (BUFFER_SIZE , sizeof (char ));
548
559
549
560
if (strlen (newBuffer ) > 0 ) { // Livestream msgs for specified channel.
@@ -556,9 +567,12 @@ void LiveStream(int newsockfd, char buffer[BUFFER_SIZE])
556
567
if (strlen (msg ) > 0 )
557
568
WriteClient (newsockfd , msg );
558
569
}
570
+ if (streaming == 0 )
571
+ break ;
559
572
if (strlen (msg ) <= 0 ) { // Livestream nothing if no msg.
560
573
WriteClient (newsockfd , "" );
561
574
}
575
+
562
576
563
577
bzero (buffer , BUFFER_SIZE );
564
578
read (newsockfd , buffer , BUFFER_SIZE );
@@ -657,6 +671,7 @@ int main(int argc, char * argv[])
657
671
Error ("ERROR, fork failed." );
658
672
}
659
673
if (pid == 0 )
674
+ {
660
675
int id_index = * shm_cliForks ;
661
676
* shm_cliForks += 1 ;
662
677
@@ -698,10 +713,14 @@ int main(int argc, char * argv[])
698
713
msg = Next (bufferg );
699
714
else
700
715
msg = NextAll ();
701
- else
702
- msg = "" ;
703
- if (strstr (bufferg , "LIVESTREAM" ) != NULL )
716
+ else if (strstr (bufferg , "LIVESTREAM" ) != NULL )
717
+ {
704
718
LiveStream (newsockfd , bufferg );
719
+ msg = "IGNORE" ;
720
+ }
721
+
722
+ else
723
+ msg = "IGNORE" ;
705
724
706
725
int n = WriteClient (newsockfd , str_append ("" , msg ));
707
726
if (n < 0 ) // Write fail, try reconnect.
0 commit comments