player: require explicit connection-call
This makes it possible to change the host and port used for connections between player and editor without recompiling the library.
This commit is contained in:
parent
bd9408fa85
commit
078e344b24
@ -118,10 +118,12 @@ int main(int argc, char *argv[])
|
||||
|
||||
sync_device *rocket = sync_create_device("sync");
|
||||
if (!rocket)
|
||||
die("something went wrong - failed to connect to host?");
|
||||
die("out of memory?");
|
||||
|
||||
#ifndef SYNC_PLAYER
|
||||
sync_set_callbacks(rocket, &bass_cb, (void *)stream);
|
||||
if (sync_connect(rocket, "localhost", SYNC_DEFAULT_PORT))
|
||||
die("failed to connect to host");
|
||||
#endif
|
||||
|
||||
/* get tracks */
|
||||
@ -144,7 +146,8 @@ int main(int argc, char *argv[])
|
||||
while (!done) {
|
||||
double row = bass_get_row(stream);
|
||||
#ifndef SYNC_PLAYER
|
||||
sync_update(rocket, (int)floor(row));
|
||||
if (sync_update(rocket, (int)floor(row)))
|
||||
sync_connect(rocket, "localhost", SYNC_DEFAULT_PORT);
|
||||
#endif
|
||||
|
||||
/* draw */
|
||||
|
||||
@ -20,11 +20,6 @@ static const char *sync_track_path(const char *base, const char *name)
|
||||
|
||||
#ifndef SYNC_PLAYER
|
||||
|
||||
#ifndef REMOTE_HOST
|
||||
#define REMOTE_HOST "localhost"
|
||||
#endif
|
||||
#define REMOTE_PORT 1338
|
||||
|
||||
static SOCKET server_connect(const char *host, int nport)
|
||||
{
|
||||
struct hostent *he;
|
||||
@ -93,7 +88,7 @@ struct sync_device *sync_create_device(const char *base)
|
||||
#ifndef SYNC_PLAYER
|
||||
d->cb = d->cb_param = NULL;
|
||||
d->row = -1;
|
||||
d->sock = server_connect(REMOTE_HOST, REMOTE_PORT);
|
||||
d->sock = INVALID_SOCKET;
|
||||
#endif
|
||||
|
||||
return d;
|
||||
@ -230,16 +225,25 @@ static int purge_and_rerequest(struct sync_device *d)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sync_connect(struct sync_device *d, const char *host, int port)
|
||||
{
|
||||
if (d->sock != INVALID_SOCKET)
|
||||
closesocket(d->sock);
|
||||
|
||||
d->sock = server_connect(host, port);
|
||||
if (d->sock == INVALID_SOCKET)
|
||||
return 1;
|
||||
|
||||
return purge_and_rerequest(d);
|
||||
}
|
||||
|
||||
int sync_update(struct sync_device *d, int row)
|
||||
{
|
||||
if (d->sock == INVALID_SOCKET) {
|
||||
d->sock = server_connect(REMOTE_HOST, REMOTE_PORT);
|
||||
if (d->sock != INVALID_SOCKET && purge_and_rerequest(d))
|
||||
goto sockerr;
|
||||
}
|
||||
if (d->sock == INVALID_SOCKET)
|
||||
return 1;
|
||||
|
||||
/* look for new commands */
|
||||
while (d->sock != INVALID_SOCKET && socket_poll(d->sock)) {
|
||||
while (socket_poll(d->sock)) {
|
||||
unsigned char cmd = 0, flag;
|
||||
int row;
|
||||
if (!recv(d->sock, (char *)&cmd, 1, 0))
|
||||
@ -288,6 +292,7 @@ int sync_update(struct sync_device *d, int row)
|
||||
return 0;
|
||||
|
||||
sockerr:
|
||||
closesocket(d->sock);
|
||||
d->sock = INVALID_SOCKET;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -22,6 +22,8 @@ struct sync_cb {
|
||||
int (*is_playing)(void *);
|
||||
};
|
||||
void sync_set_callbacks(struct sync_device *, struct sync_cb *, void *);
|
||||
#define SYNC_DEFAULT_PORT 1338
|
||||
int sync_connect(struct sync_device *, const char *, int port);
|
||||
int sync_update(struct sync_device *, int);
|
||||
#endif /* !defined(SYNC_PLAYER) */
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user