static void mock_handshake (int fd) { const uint8_t zmtp_greeting[33] = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0x7f, 3, 0, 'N', 'U', 'L', 'L', 0 }; char buffer[128]; memset(buffer, 0, sizeof(buffer)); memcpy(buffer, zmtp_greeting, sizeof(zmtp_greeting)); int rc = send(fd, buffer, 64, 0); assert(rc == 64); recv_with_retry(fd, buffer, 64); const uint8_t zmtp_ready[43] = { 4, 41, 5, 'R', 'E', 'A', 'D', 'Y', 11, 'S', 'o', 'c', 'k', 'e', 't', '-', 'T', 'y', 'p', 'e', 0, 0, 0, 6, 'D', 'E', 'A', 'L', 'E', 'R', 8, 'I', 'd', 'e', 'n', 't', 'i', 't', 'y', 0, 0, 0, 0 }; memset(buffer, 0, sizeof(buffer)); memcpy(buffer, zmtp_ready, 43); rc = send(fd, buffer, 43, 0); assert(rc == 43); recv_with_retry(fd, buffer, 43); }
static void mock_handshake (raw_socket fd_, int mock_ping_) { const uint8_t zmtp_greeting[33] = {0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0x7f, 3, 0, 'N', 'U', 'L', 'L', 0}; char buffer[128]; memset (buffer, 0, sizeof (buffer)); memcpy (buffer, zmtp_greeting, sizeof (zmtp_greeting)); int rc = TEST_ASSERT_SUCCESS_RAW_ERRNO (send (fd_, buffer, 64, 0)); TEST_ASSERT_EQUAL_INT (64, rc); recv_with_retry (fd_, buffer, 64); const uint8_t zmtp_ready[43] = { 4, 41, 5, 'R', 'E', 'A', 'D', 'Y', 11, 'S', 'o', 'c', 'k', 'e', 't', '-', 'T', 'y', 'p', 'e', 0, 0, 0, 6, 'D', 'E', 'A', 'L', 'E', 'R', 8, 'I', 'd', 'e', 'n', 't', 'i', 't', 'y', 0, 0, 0, 0}; memset (buffer, 0, sizeof (buffer)); memcpy (buffer, zmtp_ready, 43); rc = TEST_ASSERT_SUCCESS_RAW_ERRNO (send (fd_, buffer, 43, 0)); TEST_ASSERT_EQUAL_INT (43, rc); // greeting recv_with_retry (fd_, buffer, 43); if (mock_ping_) { // test PING context - should be replicated in the PONG // to avoid timeouts, do a bulk send const uint8_t zmtp_ping[12] = {4, 10, 4, 'P', 'I', 'N', 'G', 0, 0, 'L', 'O', 'L'}; uint8_t zmtp_pong[10] = {4, 8, 4, 'P', 'O', 'N', 'G', 'L', 'O', 'L'}; memset (buffer, 0, sizeof (buffer)); memcpy (buffer, zmtp_ping, 12); rc = TEST_ASSERT_SUCCESS_RAW_ERRNO (send (fd_, buffer, 12, 0)); TEST_ASSERT_EQUAL_INT (12, rc); // test a larger body that won't fit in a small message and should get // truncated memset (buffer, 'z', sizeof (buffer)); memcpy (buffer, zmtp_ping, 12); buffer[1] = 65; rc = TEST_ASSERT_SUCCESS_RAW_ERRNO (send (fd_, buffer, 67, 0)); TEST_ASSERT_EQUAL_INT (67, rc); // small pong recv_with_retry (fd_, buffer, 10); TEST_ASSERT_EQUAL_INT (0, memcmp (zmtp_pong, buffer, 10)); // large pong recv_with_retry (fd_, buffer, 23); uint8_t zmtp_pooong[65] = {4, 21, 4, 'P', 'O', 'N', 'G', 'L', 'O', 'L'}; memset (zmtp_pooong + 10, 'z', 55); TEST_ASSERT_EQUAL_INT (0, memcmp (zmtp_pooong, buffer, 23)); } }