Class: SRT::Connection

Inherits:
Object
  • Object
show all
Defined in:
ext/rbsrt/rbsrt.c

Instance Method Summary collapse

Instance Method Details

#at_closeObject



1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
# File 'ext/rbsrt/rbsrt.c', line 1375

VALUE rbsrt_connection_set_at_close_block(VALUE self)
{
    RBSRT_DEBUG_PRINT("connection set close block");

    rb_need_block();

    RBSRT_CONNECTION_UNWRAP(self, connection);

    connection->at_close_block = rb_block_proc();
    
    return Qtrue;
}

#at_dataObject

MARK: API



1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
# File 'ext/rbsrt/rbsrt.c', line 1362

VALUE rbsrt_connection_set_at_data_block(VALUE self)
{
    RBSRT_DEBUG_PRINT("connection set data block");

    rb_need_block();

    RBSRT_CONNECTION_UNWRAP(self, connection);

    connection->at_data_block = rb_block_proc();

    return Qtrue;
}

#sendmsg(message) ⇒ Object

MARK: Transmission



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
# File 'ext/rbsrt/rbsrt.c', line 795

VALUE rbsrt_socket_sendmsg(VALUE self, VALUE message)
{
    RBSRT_DEBUG_PRINT("socket sendmsg");

    RBSRT_SOCKET_BASE_UNWRAP(self, socket)

    int message_type = rb_type(message);
    const char *buf = NULL;
    int buf_len = 0;

    switch (message_type)
    {
    case T_STRING:
        buf = StringValuePtr(message);
        buf_len = (int)RSTRING_LEN(message);
        RBSRT_DEBUG_PRINT("sendmsg: %d", buf_len);
        break;

    case T_OBJECT:
    case T_DATA:
        RBSRT_DEBUG_PRINT("sendmsg DATA");
        // TODO: Support binary 
        rb_raise(rb_eArgError, "message must be a string");
        // rdata
        return FIX2INT(SRT_ERROR);
        break;
    
    default:
        rb_raise(rb_eArgError, "message must a string");

        return FIX2INT(SRT_ERROR);
        break;
    }


    // send data

    int packet_size;
    int nbytes;
    int total_nbytes = 0;
    char const *buf_p = buf; 

    do
    {
        packet_size = (buf_len - total_nbytes) > RBSRT_PAYLOAD_SIZE ? RBSRT_PAYLOAD_SIZE : (buf_len - total_nbytes);

        nbytes = srt_sendmsg2(socket->socket, (buf_p + total_nbytes), packet_size, NULL);

        if (nbytes == SRT_ERROR)
        {
            DEBUG_ERROR_PRINT("sendmsg error. %s", srt_getlasterror_str());

            rbsrt_raise_last_srt_error();

            break;
        }

        RBSRT_DEBUG_PRINT("send bytes %d", nbytes);
    } 
    while ((total_nbytes += nbytes) < buf_len);

    return INT2FIX(total_nbytes);
}