float BounceInterpolator::interpolate(float t) {
    t *= 1.1226f;
    if (t < 0.3535f) return bounce(t);
    else if (t < 0.7408f) return bounce(t - 0.54719f) + 0.7f;
    else if (t < 0.9644f) return bounce(t - 0.8526f) + 0.9f;
    else return bounce(t - 1.0435f) + 0.95f;
}
Exemple #2
0
    void update(float elapsed) {
        _x += _xSpeed * elapsed;
        _y += _ySpeed * elapsed;

        if (_x < 0) {
            _rightPlayer->incrementScore();
            reset();
            shouldUpdateTitle = true;
        }

        if (_x > SCREEN_WIDTH - BALL_SIZE) {
            _leftPlayer->incrementScore();
            reset();
            shouldUpdateTitle = true;
        }

        if (_y < 0 || _y > SCREEN_HEIGHT - BALL_SIZE) {
            _ySpeed = -_ySpeed;
        }

        const Rect ballRect(_x, _y, BALL_SIZE, BALL_SIZE);

        const Rect leftPlayerCoords = _leftPlayer->getCoords();
        if (leftPlayerCoords.intersects(ballRect)) {
            bounce(*_leftPlayer, _xSpeed, _ySpeed);
        }

        const Rect rightPlayerCoords = _rightPlayer->getCoords();
        if (rightPlayerCoords.intersects(ballRect)) {
            bounce(*_rightPlayer, _xSpeed, _ySpeed);
            _xSpeed = -_xSpeed;
        }
    }
SETUP_TEARDOWN_TESTCONTEXT

void test_reconnect_ivl_against_pair_socket (const char *my_endpoint_,
                                             void *sb_)
{
    void *sc = test_context_socket (ZMQ_PAIR);
    int interval = -1;
    TEST_ASSERT_SUCCESS_ERRNO (
      zmq_setsockopt (sc, ZMQ_RECONNECT_IVL, &interval, sizeof (int)));
    TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint_));

    bounce (sb_, sc);

    TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb_, my_endpoint_));

    expect_bounce_fail (sb_, sc);

    TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb_, my_endpoint_));

    expect_bounce_fail (sb_, sc);

    TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint_));

    bounce (sb_, sc);

    test_context_socket_close (sc);
}
Exemple #4
0
void		balls_update(t_ball *ball, float size)
{
	float min;
	float max;
	float b_min;
	float b_max;

	min = -1.0f + 0.03f;
	max = 1.0f - 0.03f;
	b_min = ball->player->bar.position;
	b_max = ball->player->bar.position + size;
	ball->position.x += ball->direction.x * ball->speed;
	ball->position.y += ball->direction.y * ball->speed;
	check_block(ball);
	if (ball->position.x <= min)
		bounce(1, ball);
	if (ball->position.x >= max)
		bounce(1, ball);
	if (ball->position.x + 0.03f >= b_min && ball->position.x - 0.03f <= b_max)
		bounce_bar(b_min, b_max, ball);
	if (ball->position.y <= min)
		lost(ball);
	if (ball->position.y >= max)
	{
		ball->direction.y *= -1;
		ball->position.y += ball->direction.y * ball->speed;
	}
}
Exemple #5
0
bool
Haywire::collision_squished(GameObject& object)
{
  auto player = dynamic_cast<Player*>(&object);
  if (player && player->is_invincible()) {
    player->bounce (*this);
    kill_fall();
    return true;
  }

  if (is_stunned) {
    if (player)
      player->bounce (*this);
    return true;
  }

  if(WalkingBadguy::is_frozen()) {
    WalkingBadguy::unfreeze();
  }

  if (!is_exploding) {
    start_exploding();
  }

  time_stunned = TIME_STUNNED;
  is_stunned = true;
  physic.set_velocity_x(0.f);
  physic.set_acceleration_x(0.f);

  if (player)
    player->bounce (*this);

  return true;
}
Exemple #6
0
 float value(float t, float b, float c, float d)
 {
     if(In == _t)
         return c - bounce(d - t, 0, c, d) + b;
     else
         return bounce(t, b, c, d);
 }
Exemple #7
0
void updateNrender(){
    float a, b;
    float time;
    u32 ms;
    getTimeElapsed(&ms);
    time = ms / 1000.f;
    getMousePosition(&a, &b);
    paddleX = s2p(a);
    paddleRot = s2p(b);
    static float rotate = 0;
    static float vx = 0, vy = -1, px = 0, py = 0, av =0;
    static char hasBounced = 0;

    rotate += av*time;
    px += time*vx, py += time*vy;
    square_rotateTo(ball, rotate);
    square_traslateTo(ball, px, py);

    square_traslateTo(paddle, paddleX, paddleY);
    square_rotateTo(paddle, paddleRot);

    squareList_update_pos(Sprites.squareList, buffer);

    //CHECK COLLISION :)
    if(hasBounced!= 1 && px <-1){ bounce(TAU/4, &vx, &vy, &av, 1.);hasBounced = 1; }
    if(hasBounced!=2 && px> 1){ bounce(-TAU/4, &vx, &vy, &av, 1.);hasBounced = 2;}
    if(hasBounced!=3 && py >1){ bounce(-TAU/2, &vx, &vy, &av, 1.); hasBounced = 3; }
    if(py <-1){
        game_die();
    }
    if(hasBounced!=4 && px<= paddleX+0.4 && px>=paddleX-0.4  && py<=paddleY+0.05 && py>=paddleY-0.05) {
        bounce(3/4*TAU-paddleRot, &vx, &vy, &av, 1.2);
        hasBounced = 4;
        score++;
    }
    puun_MouseClick click;
    getMouseClick(&click);
    puun_KEY key;
    getKeyboardKey(&key);
    if(click)
        printf("MOUSE CLICKED\n");
    if(key.isPressed) printf("%c\n", key.key);




    glClearColor(1.0, 1.0, 1.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    renderSpriteList(Sprites);
    //uniImg.id = ballId;
    //uniImg.texnum = 0;
    //render_squareList(Squares, (Data)&uniImg, 1);


    puun_SWAP_BUFFERS();
    //SDL_GL_SwapBuffers();
}
Exemple #8
0
/* generate pretty colours by bouncing rgb values up and down */
void set_colour(void)
{
    if (randomcolours) {
        glColor3f(frand(), frand(), frand());
    } else {
        bounce(&r, &dr);
        bounce(&g, &dg);
        bounce(&b, &db);
        glColor3f(r, g, b);
    }
}
static void* draw_proc(void* context) {
    const int OVALW = 32;
    const int OVALH = 32;

    const SkBitmap* bm = static_cast<const SkBitmap*>(context);
    SkFlipPixelRef* ref = static_cast<SkFlipPixelRef*>(bm->pixelRef());

    const int DSCALE = 1;
    SkScalar    dx = SkIntToScalar(7) / DSCALE;
    SkScalar    dy = SkIntToScalar(5) / DSCALE;
    SkScalar    x = 0;
    SkScalar    y = 0;

    SkPaint paint;
    
    paint.setAntiAlias(true);
    paint.setColor(SK_ColorRED);
    
    SkRect oval;
    oval.setEmpty();

    while (!gDone) {
        ref->inval(oval, true);
        oval.set(x, y, x + SkIntToScalar(OVALW), y + SkIntToScalar(OVALH));
        ref->inval(oval, true);

        SkAutoFlipUpdate    update(ref);
        
        if (!update.dirty().isEmpty()) {
            // this must be local to the loop, since it needs to forget the pixels
            // its writing to after each iteration, since we do the swap
            SkCanvas    canvas(update.bitmap());

//            SkDebugf("----- dirty [%d %d %d %d]\n", dirty.getBounds().fLeft, dirty.getBounds().fTop, dirty.getBounds().width(), dirty.getBounds().height());
            canvas.clipRegion(update.dirty());
            
            canvas.drawColor(0, SkXfermode::kClear_Mode);            
            canvas.drawOval(oval, paint);
        }
        bounce(&x, &dx, WIDTH-OVALW);
        bounce(&y, &dy, HEIGHT-OVALH);
        
#if 1
        for (int i = 0; i < 1000; i++) {
            for (int j = 0; j < 10000; j++) {
                SkFixedMul(j, 10);
            }
        }
#endif
    }
    return NULL;
}
Exemple #10
0
static void ball(struct pong *p)
{
    int oldx = p->ball.x/RES;
    int oldy = p->ball.y/RES;

    int newx;
    int newy;

    int info;

    /* movement */
    p->ball.x += p->ball.speedx;
    p->ball.y += p->ball.speedy;

    newx = p->ball.x/RES;
    newy = p->ball.y/RES;

    /* detect if ball hits a wall */
    if(newy + BALL_HEIGHT > LCD_HEIGHT) {
        /* hit floor, bounce */
        p->ball.speedy = -p->ball.speedy;
        p->ball.y = (LCD_HEIGHT - BALL_HEIGHT) * RES;
    }
    else if(newy < 0) {
        /* hit ceiling, bounce */
        p->ball.speedy = -p->ball.speedy;
        p->ball.y = 0;
    }

    /* detect if ball hit pads */
    if(padcollide(p, 0, &info))
        bounce(p, 0, info);
    else if(padcollide(p, 1, &info))
        bounce(p, 1, info);
    else if(wallcollide(p, 0))
        score(p, 1);
    else if(wallcollide(p, 1))
        score(p, 0);

    newx = p->ball.x/RES;
    newy = p->ball.y/RES;

    /* clear old position */
    rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
    rb->lcd_fillrect(oldx, oldy, BALL_WIDTH, BALL_HEIGHT);
    rb->lcd_set_drawmode(DRMODE_SOLID);

    /* draw the new ball position */
    rb->lcd_fillrect(newx, newy, BALL_WIDTH, BALL_HEIGHT);
}
Exemple #11
0
int main (void)
{
    setup_test_environment();
    void *ctx = zmq_ctx_new ();
    assert (ctx);

    void *sb = zmq_socket (ctx, ZMQ_PAIR);
    assert (sb);
    int rc = zmq_bind (sb, "ipc:///tmp/tester");
    assert (rc == 0);

    void *sc = zmq_socket (ctx, ZMQ_PAIR);
    assert (sc);
    rc = zmq_connect (sc, "ipc:///tmp/tester");
    assert (rc == 0);
    
    bounce (sb, sc);

    rc = zmq_close (sc);
    assert (rc == 0);

    rc = zmq_close (sb);
    assert (rc == 0);

    rc = zmq_ctx_term (ctx);
    assert (rc == 0);

    return 0 ;
}
Exemple #12
0
int XS_TEST_MAIN ()
{
    fprintf (stderr, "pair_tcp test running...\n");

    void *ctx = xs_init ();
    assert (ctx);

    void *sb = xs_socket (ctx, XS_PAIR);
    assert (sb);
    int rc = xs_bind (sb, "tcp://127.0.0.1:5560");
    assert (rc == 0);

    void *sc = xs_socket (ctx, XS_PAIR);
    assert (sc);
    rc = xs_connect (sc, "tcp://127.0.0.1:5560");
    assert (rc == 0);
    
    bounce (sb, sc);

    rc = xs_close (sc);
    assert (rc == 0);

    rc = xs_close (sb);
    assert (rc == 0);

    rc = xs_term (ctx);
    assert (rc == 0);

    return 0 ;
}
Exemple #13
0
void render() {
    IOWR_ALTERA_AVALON_TIMER_STATUS (TIMER_BASE, 0);

    move(&p_pos, &p_spd);

    if (p_pos.y > 800 || p_pos.y < 0) {
        p_pos.y = (p_pos.y < 2048 && p_pos.y > 0) ? 800 : 0;
    }

    if (collide(&BALL, &PADDLE, &b_pos, &p_pos,
                &b_spd, &p_spd)) {
        b_spd.dx  = -b_spd.dx + 10;
        b_spd.dy += (b_pos.y - p_pos.y - 99) / 10;
    }
    else if (b_pos.x + b_spd.dx < p_pos.x || b_pos.x + b_spd.dx > 2048) {
        b_pos.x = 500;
        b_pos.y = 500,
              b_spd.dx = -10;
        b_spd.dy = -10;
    }

    if (b_spd.dy > 40) b_spd.dy = 40;
    if (b_spd.dy < -40) b_spd.dy = -40;

    bounce(&BALL, &b_pos, &b_spd, &SCREEN);
    move(&b_pos, &b_spd);
    if (b_pos.y < 0 || b_pos.y > 1023) b_pos.y = 0;

    draw(&BALL,&b_pos);
    draw(&PADDLE,&p_pos);
    switch_frames();

}
Exemple #14
0
int main (void)
{
    fprintf (stderr, "test_pair_ipc running...\n");

    void *ctx = zmq_init (1);
    assert (ctx);

    void *sb = zmq_socket (ctx, ZMQ_PAIR);
    assert (sb);
    int rc = zmq_bind (sb, "ipc:///tmp/tester");
    assert (rc == 0);

    void *sc = zmq_socket (ctx, ZMQ_PAIR);
    assert (sc);
    rc = zmq_connect (sc, "ipc:///tmp/tester");
    assert (rc == 0);
    
    bounce (sb, sc);

    rc = zmq_close (sc);
    assert (rc == 0);

    rc = zmq_close (sb);
    assert (rc == 0);

    rc = zmq_term (ctx);
    assert (rc == 0);

    return 0 ;
}
Exemple #15
0
int main (void)
{
    void *ctx = zmq_ctx_new ();
    assert (ctx);

    void *sb = zmq_socket (ctx, ZMQ_REP);
    assert (sb);
    int rc = zmq_bind (sb, "tcp://127.0.0.1:5560");
    assert (rc == 0);

    void *sc = zmq_socket (ctx, ZMQ_REQ);
    assert (sc);
    rc = zmq_connect (sc, "tcp://127.0.0.1:5560");
    assert (rc == 0);
    
    bounce (sb, sc);

    rc = zmq_close (sc);
    assert (rc == 0);

    rc = zmq_close (sb);
    assert (rc == 0);

    rc = zmq_ctx_term (ctx);
    assert (rc == 0);

    return 0 ;
}
Exemple #16
0
void Sw::update(){
  byte temp;
  
  PORTD = PORTD & SH_Pin_LOW_Mask;
  PORTD = PORTD | SH_Pin_HIGH_Mask;
  
  for(int i=0;i<8;i++){
    last_Sw_State[0][i] = current_Sw_State[0][i];
    last_Sw_State[1][i] = current_Sw_State[1][i];
    
    temp = ~(PINB & 0b00000011);
    
    if((temp & pin_Out1_Mask) == 0b01){
      current_Sw_State[0][i] = true;
    }else{
      current_Sw_State[0][i] = false;
    }
    
    if((temp & pin_Out2_Mask) == 0b10){
      current_Sw_State[1][i] = true;
    }else{
      current_Sw_State[1][i] = false;
    }
    
    PORTD = PORTD & CLK_Pin_LOW_Mask;
    PORTD = PORTD | CLK_Pin_HIGH_Mask;
  }
  bounce();
}
Exemple #17
0
void test_simple (void)
{
    char my_endpoint[256];
    void *ctx = zmq_ctx_new ();
    assert (ctx);

    void *sb = zmq_socket (ctx, ZMQ_REP);
    assert (sb);
    int rc = zmq_bind (sb, "ipc://*");
    assert (rc == 0);
    size_t len = sizeof(my_endpoint);
    rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, my_endpoint, &len);
    assert (rc == 0);

    void *sc = zmq_socket (ctx, ZMQ_REQ);
    assert (sc);
    rc = zmq_connect (sc, my_endpoint);
    assert (rc == 0);
    
    bounce (sb, sc);

    rc = zmq_close (sc);
    assert (rc == 0);

    rc = zmq_close (sb);
    assert (rc == 0);

    rc = zmq_ctx_term (ctx);
    assert (rc == 0);
}
Exemple #18
0
int main (void)
{
    if (!is_tipc_available ()) {
        printf ("TIPC environment unavailable, skipping test\n");
        return 77;
    }

    fprintf (stderr, "test_pair_tipc running...\n");

    void *ctx = zmq_init (1);
    assert (ctx);

    void *sb = zmq_socket (ctx, ZMQ_PAIR);
    assert (sb);
    int rc = zmq_bind (sb, "tipc://{5560,0,0}");
    assert (rc == 0);

    void *sc = zmq_socket (ctx, ZMQ_PAIR);
    assert (sc);
    rc = zmq_connect (sc, "tipc://{5560,0}@0.0.0");
    assert (rc == 0);

    bounce (sb, sc);

    rc = zmq_close (sc);
    assert (rc == 0);

    rc = zmq_close (sb);
    assert (rc == 0);

    rc = zmq_ctx_term (ctx);
    assert (rc == 0);

    return 0;
}
void monitorable_actor::bounce(mailbox_element_ptr& what) {
  error err;
  shared_critical_section([&] {
    err = fail_state_;
  });
  bounce(what, err);
}
Exemple #20
0
void Switch::startBouncing() {
	if (m_pBounceResistance) {
		// Already active?
		return;
	}

	if (!m_pComponent->circuitDocument()) return;

// 	kDebug() << k_funcinfo << endl;

	m_pBounceResistance = m_pComponent->createResistance(m_pP1, m_pP2, 10000);
	m_bounceStart = Simulator::self()->time();

//FIXME: I broke the bounce feature when I cleaned this out of the simulator,
// should probably be put into circuit document or some other solution which doesn't
// contaminate that many other classes.

//	Simulator::self()->attachSwitch( this );
// 	kDebug() << "m_bounceStart="<<m_bounceStart<<" m_bouncePeriod_ms="<<m_bouncePeriod_ms<<endl;

	// initialize random generator
	srand(time(NULL));

	// Give our bounce resistor an initial value
	bounce();
}
Exemple #21
0
void test_single_connect_ipv4 (void)
{
    void *ctx = zmq_ctx_new ();
    assert (ctx);

    void *sb = zmq_socket (ctx, ZMQ_REP);
    assert (sb);
    int rc = zmq_bind (sb, "tcp://127.0.0.1:5560");
    assert (rc == 0);

    void *sc = zmq_socket (ctx, ZMQ_REQ);
    assert (sc);
    rc = zmq_connect (sc, "tcp://127.0.0.1:5560");
    assert (rc == 0);
    
    bounce (sb, sc);

    rc = zmq_disconnect (sc, "tcp://127.0.0.1:5560");
    assert (rc == 0);

    rc = zmq_unbind (sb, "tcp://127.0.0.1:5560");
    assert (rc == 0);

    rc = zmq_close (sc);
    assert (rc == 0);

    rc = zmq_close (sb);
    assert (rc == 0);

    rc = zmq_ctx_term (ctx);
    assert (rc == 0);
}
Exemple #22
0
int main (void)
{
    fprintf (stderr, "test_reqrep_tipc running...\n");

    void *ctx = zmq_init (1);
    assert (ctx);

    void *sb = zmq_socket (ctx, ZMQ_REP);
    assert (sb);
    int rc = zmq_bind (sb, "tipc://{5560,0,0}");
    assert (rc == 0);

    void *sc = zmq_socket (ctx, ZMQ_REQ);
    assert (sc);
    rc = zmq_connect (sc, "tipc://{5560,0}@0.0.0");
    assert (rc == 0);

    bounce (sb, sc);

    rc = zmq_close (sc);
    assert (rc == 0);

    rc = zmq_close (sb);
    assert (rc == 0);

    rc = zmq_ctx_term (ctx);
    assert (rc == 0);

    return 0;
}
Exemple #23
0
int main (int argc, char *argv [])
{
    void *ctx = zmq_init (1);
    assert (ctx);

    void *sb = zmq_socket (ctx, ZMQ_REP);
    assert (sb);
    int rc = zmq_bind (sb, "tcp://127.0.0.1:5555");
    assert (rc == 0);

    void *sc = zmq_socket (ctx, ZMQ_REQ);
    assert (sc);
    rc = zmq_connect (sc, "tcp://127.0.0.1:5555");
    assert (rc == 0);
    
    bounce (sb, sc);

    rc = zmq_close (sc);
    assert (rc == 0);

    rc = zmq_close (sb);
    assert (rc == 0);

    rc = zmq_term (ctx);
    assert (rc == 0);

    return 0 ;
}
Exemple #24
0
SETUP_TEARDOWN_TESTCONTEXT

void test_diffserv ()
{
    int tos = 0x28;
    int o_tos;
    size_t tos_size = sizeof (tos);
    char my_endpoint[MAX_SOCKET_STRING];

    void *sb = test_context_socket (ZMQ_PAIR);
    TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (sb, ZMQ_TOS, &tos, tos_size));
    bind_loopback_ipv4 (sb, my_endpoint, sizeof (my_endpoint));

    TEST_ASSERT_SUCCESS_ERRNO (zmq_getsockopt (sb, ZMQ_TOS, &o_tos, &tos_size));
    TEST_ASSERT_EQUAL (tos, o_tos);

    void *sc = test_context_socket (ZMQ_PAIR);
    tos = 0x58;
    TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (sc, ZMQ_TOS, &tos, tos_size));
    TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint));
    TEST_ASSERT_SUCCESS_ERRNO (zmq_getsockopt (sc, ZMQ_TOS, &o_tos, &tos_size));
    TEST_ASSERT_EQUAL (tos, o_tos);

    // Wireshark can be used to verify that the server socket is
    // using DSCP 0x28 in packets to the client while the client
    // is using 0x58 in packets to the server.
    bounce (sb, sc);

    test_context_socket_close (sc);
    test_context_socket_close (sb);
}
Exemple #25
0
bool
MrBomb::collision_squished(GameObject& object)
{
  auto player = dynamic_cast<Player*>(&object);
  if (player && player->is_invincible()) {
    player->bounce(*this);
    kill_fall();
    return true;
  }
  if (is_valid()) {
    auto& bomb = Sector::get().add<Bomb>(get_pos(), m_dir, m_sprite_name);

    // Do not trigger dispenser because we need to wait for
    // the bomb instance to explode.
    if (get_parent_dispenser() != nullptr)
    {
      bomb.set_parent_dispenser(get_parent_dispenser());
      set_parent_dispenser(nullptr);
    }

    remove_me();
  }
  kill_squished(object);
  return true;
}
Exemple #26
0
int XS_TEST_MAIN ()
{
    fprintf (stderr, "reqrep_ipc test running...\n");

    void *ctx = xs_init ();
    assert (ctx);

    void *sb = xs_socket (ctx, XS_REP);
    assert (sb);
    int rc = xs_bind (sb, "ipc:///tmp/tester");
    assert (rc == 0);

    void *sc = xs_socket (ctx, XS_REQ);
    assert (sc);
    rc = xs_connect (sc, "ipc:///tmp/tester");
    assert (rc == 0);
    
    bounce (sb, sc);

    rc = xs_close (sc);
    assert (rc == 0);

    rc = xs_close (sb);
    assert (rc == 0);

    rc = xs_term (ctx);
    assert (rc == 0);

    return 0 ;
}
Exemple #27
0
int main (void)
{
    setup_test_environment();
    void *ctx = zmq_ctx_new ();
    assert (ctx);

    void *sb = zmq_socket (ctx, ZMQ_PAIR);
    assert (sb);
    int rc = zmq_bind (sb, "ipc://*");
    assert (rc == 0);

    char endpoint [200];
    size_t size = sizeof (endpoint);
    rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, endpoint, &size);
    assert (rc == 0);

    void *sc = zmq_socket (ctx, ZMQ_PAIR);
    assert (sc);
    rc = zmq_connect (sc, endpoint);
    assert (rc == 0);
    
    bounce (sb, sc);

    rc = zmq_close (sc);
    assert (rc == 0);

    rc = zmq_close (sb);
    assert (rc == 0);

    rc = zmq_ctx_term (ctx);
    assert (rc == 0);

    return 0 ;
}
void test_pair ()
{
    void *ctx = zmq_ctx_new ();
    assert (ctx);

    void *sb = zmq_socket (ctx, ZMQ_PAIR);
    assert (sb);

    pre_allocate_sock(sb, "/tmp/tester");

    int rc = zmq_bind (sb, "ipc:///tmp/tester");
    assert (rc == 0);

    void *sc = zmq_socket (ctx, ZMQ_PAIR);
    assert (sc);
    rc = zmq_connect (sc, "ipc:///tmp/tester");
    assert (rc == 0);

    bounce (sb, sc);

    rc = zmq_close (sc);
    assert (rc == 0);

    rc = zmq_close (sb);
    assert (rc == 0);

    rc = zmq_ctx_term (ctx);
    assert (rc == 0);

    rc = unlink ("/tmp/tester");
    assert (rc == 0);
}
void test_pair ()
{
    void *ctx = zmq_ctx_new ();
    assert (ctx);

    void *sb = zmq_socket (ctx, ZMQ_PAIR);
    assert (sb);

    pre_allocate_sock(sb, "127.0.0.1", "5560");

    int rc = zmq_bind (sb, "tcp://127.0.0.1:5560");
    assert (rc == 0);

    void *sc = zmq_socket (ctx, ZMQ_PAIR);
    assert (sc);
    rc = zmq_connect (sc, "tcp://127.0.0.1:5560");
    assert (rc == 0);

    bounce (sb, sc);

    rc = zmq_close (sc);
    assert (rc == 0);

    rc = zmq_close (sb);
    assert (rc == 0);

    rc = zmq_ctx_term (ctx);
    assert (rc == 0);
}
Exemple #30
0
void test_pair_tcp_connect_by_name ()
{
    // all other tcp test cases bind to a loopback wildcard address, then
    // retrieve the bound endpoint, which is numerical, and use that to
    // connect. this test cases specifically uses "localhost" to connect
    // to ensure that names are correctly resolved
    void *sb = test_context_socket (ZMQ_PAIR);

    char bound_endpoint[MAX_SOCKET_STRING];
    bind_loopback_ipv4 (sb, bound_endpoint, sizeof bound_endpoint);

    // extract the bound port number
    const char *pos = strrchr (bound_endpoint, ':');
    TEST_ASSERT_NOT_NULL (pos);
    const char connect_endpoint_prefix[] = "tcp://localhost";
    char connect_endpoint[MAX_SOCKET_STRING];
    strcpy (connect_endpoint, connect_endpoint_prefix);
    strcat (connect_endpoint, pos);

    void *sc = test_context_socket (ZMQ_PAIR);

    TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, connect_endpoint));

    bounce (sb, sc);

    test_context_socket_close (sc);
    test_context_socket_close (sb);
}