/rusxmms/librcc

To get this branch, use:
bzr branch http://suren.me/webbzr/rusxmms/librcc

« back to all changes in this revision

Viewing changes to src/rccexternal.c

  • Committer: Suren A. Chilingaryan
  • Date: 2010-07-16 07:58:26 UTC
  • Revision ID: csa@dside.dyndns.org-20100716075826-4rvnh4iccqrqsdfj
Windows fixes and CMake scripts to build under Windows

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
#define RCC_EXT_PROG_NAME "rccexternal"
65
65
#define RCC_EXTERNAL_TIMEOUT                    250 /* 100us */
66
66
 
 
67
#ifdef HAVE_UNISTD_H
67
68
static pid_t pid = (pid_t)-1;
68
69
static char *addr = NULL;
 
70
#endif /* HAVE_UNISTD_H */
69
71
 
70
72
int rccExternalInit() {
71
 
#ifdef HAVE_SIGNAL_H
 
73
#ifdef HAVE_UNISTD_H
 
74
# ifdef HAVE_SIGNAL_H
72
75
    struct sigaction act;
 
76
# endif /* HAVE_SIGNAL_H */
 
77
# ifdef HAVE_SYS_STAT_H
73
78
    struct stat st;
74
 
#endif /* HAVE_SIGNAL_H */
 
79
# endif /* HAVE_SYS_STAT_H */
75
80
 
76
81
    if (pid != (pid_t)-1) return 0;
77
82
 
85
90
        if (pid == (pid_t)-1) return -1;
86
91
        sprintf(addr,"%s/.rcc/comm/%lu.sock", rcc_home_dir, (unsigned long)pid);
87
92
 
88
 
#ifdef HAVE_SIGNAL_H
 
93
# ifdef HAVE_SIGNAL_H
89
94
        act.sa_handler = SIG_IGN;
90
95
        sigemptyset(&act.sa_mask);
91
96
        act.sa_flags = 0;
92
97
        sigaction(SIGPIPE,&act,NULL);
93
 
#endif /* HAVE_SIGNAL_H */
 
98
# endif /* HAVE_SIGNAL_H */
94
99
 
95
100
        return 0;
96
101
    }
97
102
 
98
103
    /*if ((!stat("../external/" RCC_EXT_PROG_NAME, &st))&&(st.st_mode&S_IXOTH)) {
99
104
        execl ("../external/" RCC_EXT_PROG_NAME, RCC_EXT_PROG_NAME, NULL);
100
 
    } else*/ if ((!stat(LIBRCC_DATA_DIR "/" RCC_EXT_PROG_NAME, &st))&&(st.st_mode&S_IXOTH)) {
 
105
    } else*/ 
 
106
# ifdef HAVE_SYS_STAT_H
 
107
    if ((!stat(LIBRCC_DATA_DIR "/" RCC_EXT_PROG_NAME, &st))&&(st.st_mode&S_IXOTH)) {
 
108
# endif /* HAVE_SYS_STAT_H */
101
109
        execl(LIBRCC_DATA_DIR "/" RCC_EXT_PROG_NAME, RCC_EXT_PROG_NAME, NULL);
 
110
# ifdef HAVE_SYS_STAT_H
102
111
    }
 
112
# endif /* HAVE_SYS_STAT_H */
 
113
#endif /* HAVE_UNISTD_H */
103
114
    exit(1);
104
115
}
105
116
 
106
117
void rccExternalFree() {
 
118
#ifdef HAVE_UNISTD_H
107
119
    int retry;
108
120
    pid_t res;
109
121
    struct timespec timeout = { 0, 5000000 };
122
134
 
123
135
    pid = (pid_t)-1;
124
136
    if (addr) free(addr);
125
 
 
 
137
#endif /* HAVE_UNISTD_H */
126
138
}
127
139
 
 
140
#ifdef HAVE_SYS_SELECT_H
128
141
static int rccExternalSetDeadline(struct timeval *tv, unsigned long timeout) {
129
142
/*
130
143
    gettimeofday(tv, NULL);
135
148
    tv->tv_usec = (timeout + RCC_EXTERNAL_TIMEOUT) % 1000000;
136
149
    return 0;
137
150
}
 
151
#endif /* HAVE_SYS_SELECT_H */
138
152
 
139
153
size_t rccExternalWrite(int s, const char *buffer, ssize_t size, unsigned long timeout) {
 
154
#ifdef HAVE_SYS_SELECT_H
140
155
    int err;
141
156
    unsigned char connected = 1;
142
157
    ssize_t writed, res = 0;
158
173
    }
159
174
 
160
175
    return size - writed;
 
176
#else /* HAVE_SYS_SELECT_H */
 
177
    return -1;
 
178
#endif /* HAVE_SYS_SELECT_H */
161
179
}
162
180
 
163
181
size_t rccExternalRead(int s, char *buffer, ssize_t size, unsigned long timeout) {
 
182
#ifdef HAVE_SYS_SELECT_H
164
183
    int err;
165
184
    unsigned char connected = 1;
166
185
    ssize_t readed, res = 0;
182
201
    }
183
202
 
184
203
    return size - readed;
 
204
#else /* HAVE_SYS_SELECT_H */
 
205
    return -1;
 
206
#endif /* HAVE_SYS_SELECT_H */
185
207
}
186
208
 
187
209
int rccExternalConnect(unsigned char module) {
 
210
#ifdef HAVE_SYS_SOCKET_H
188
211
    int err;
189
212
    int retries = 10;
190
213
    int sock;
241
264
    }
242
265
 
243
266
    return sock;
 
267
#else /* HAVE_SYS_SOCKET_H */
 
268
    return -1;
 
269
#endif /* HAVE_SYS_SOCKET_H */
244
270
}
245
271
 
246
272
void rccExternalClose(int s) {
 
273
#ifdef HAVE_SYS_SOCKET_H
247
274
    unsigned char cmd = 0;
248
275
    if (s != -1) {
249
276
        write(s, &cmd, 1);
250
277
        close(s);
251
278
    }
 
279
#endif /* HAVE_SYS_SOCKET_H */
252
280
}
253
281
 
254
282
int rccExternalAllowOfflineMode() {