MCPcopy Create free account
hub / github.com/SIPp/sipp / empty

Method empty

src/socket.cpp:840–915  ·  view source on GitHub ↗

Pull up to tcp_readsize data bytes out of the socket into our local buffer. */

Source from the content-addressed store, hash-verified

838
839/* Pull up to tcp_readsize data bytes out of the socket into our local buffer. */
840int SIPpSocket::empty()
841{
842
843 int readsize=0;
844 if (ss_transport == T_UDP || ss_transport == T_SCTP) {
845 readsize = SIPP_MAX_MSG_SIZE;
846 } else {
847 readsize = tcp_readsize;
848 }
849
850 struct socketbuf *socketbuf;
851 char *buffer;
852 int ret = -1;
853 /* Where should we start sending packets to, ideally we should begin to parse
854 * the Via, Contact, and Route headers. But for now SIPp always sends to the
855 * host specified on the command line; or for UAS mode to the address that
856 * sent the last message. */
857 sipp_socklen_t addrlen = sizeof(struct sockaddr_storage);
858
859 buffer = (char *)malloc(readsize);
860 if (!buffer) {
861 ERROR("Could not allocate memory for read!");
862 }
863 socketbuf = alloc_socketbuf(buffer, readsize, NO_COPY, nullptr);
864
865 switch(ss_transport) {
866 case T_TCP:
867 case T_UDP:
868 ret = recvfrom(ss_fd, buffer, readsize, 0, (struct sockaddr *)&socketbuf->addr, &addrlen);
869 break;
870 case T_TLS:
871#if defined(USE_OPENSSL) || defined(USE_WOLFSSL)
872 ret = SSL_read(ss_ssl, buffer, readsize);
873 /* XXX: Check for clean shutdown. */
874#else
875 ERROR("TLS support is not enabled!");
876#endif
877 break;
878 case T_SCTP:
879#ifdef USE_SCTP
880 struct sctp_sndrcvinfo recvinfo;
881 memset(&recvinfo, 0, sizeof(recvinfo));
882 int msg_flags = 0;
883
884 ret = sctp_recvmsg(ss_fd, (void*)buffer, readsize,
885 (struct sockaddr *) &socketbuf->addr, &addrlen, &recvinfo, &msg_flags);
886
887 if (MSG_NOTIFICATION & msg_flags) {
888 errno = 0;
889 handleSCTPNotify(buffer);
890 ret = -2;
891 }
892#else
893 ERROR("SCTP support is not enabled!");
894#endif
895 break;
896 }
897 if (ret <= 0) {

Callers 15

FileContentsMethod · 0.80
set_usersMethod · 0.80
get_remote_media_addrMethod · 0.80
process_incomingMethod · 0.80
traffic_threadFunction · 0.80
socket.cppFile · 0.80
encryptVectorMethod · 0.80
decryptVectorMethod · 0.80

Calls 3

ERRORFunction · 0.85
alloc_socketbufFunction · 0.85
free_socketbufFunction · 0.85

Tested by

no test coverage detected