~phablet-team/libiphb/master

« back to all changes in this revision

Viewing changes to src/libiphb.c

  • Committer: Simo Piiroinen
  • Date: 2014-03-24 09:19:48 UTC
  • mfrom: (35.1.3)
  • Revision ID: git-v1:4c532acaf7243b9fa952aeaf7c1f0dce1d77f3b3
Merge pull request #7 from spiiroin/32bit_iphb_ranges

Support 32bit iphb wakeup ranges

Show diffs side-by-side

added added

removed removed

Lines of Context:
166
166
 
167
167
 
168
168
time_t
169
 
iphb_wait(iphb_t iphbh, unsigned short mintime, unsigned short maxtime, int must_wait)
 
169
iphb_wait2(iphb_t iphbh, unsigned mintime, unsigned maxtime, int must_wait, int resume)
170
170
{
171
171
  struct _iphb_req_t  req = {IPHB_WAIT};
172
172
  struct _iphb_wait_resp_t resp = {0};
178
178
 
179
179
  (void)suck_data(HB_INST(iphbh)->fd);
180
180
 
181
 
  req.u.wait.mintime = mintime;
182
 
  req.u.wait.maxtime = maxtime;
183
 
  req.u.wait.pid = getpid();
 
181
  /* There are apps that contain out of date libiphb versions built
 
182
   * in to the application binaries and we need to at least attempt
 
183
   * not to break handling of iphb requests that used to be ok.
 
184
   *
 
185
   * Originally the version field did not exist, but the area now
 
186
   * occupied by it was initialized to zero. By setting it now to
 
187
   * a non-zero value, we can signal the server side that additional
 
188
   * fields are in use.
 
189
   *
 
190
   * Version 1 adds: mintime_hi, maxtime_hi and wakeup fields
 
191
   */
 
192
  req.u.wait.version    = 1;
 
193
 
 
194
  /* Originally mintime and maxtime were 16 bits wide. As we must
 
195
   * keep the structure layout compatible with it, the extension
 
196
   * to 32bit range is done by having upper halfs stored separately.
 
197
   * The Server side ignores upper parts unless version >= 1.  */
 
198
  req.u.wait.mintime    = (mintime >>  0) & 0xffff;
 
199
  req.u.wait.mintime_hi = (mintime >> 16) & 0xffff;
 
200
  req.u.wait.maxtime    = (maxtime >>  0) & 0xffff;
 
201
  req.u.wait.maxtime_hi = (maxtime >> 16) & 0xffff;
 
202
 
 
203
  /* Client process id */
 
204
  req.u.wait.pid        = getpid();
 
205
 
 
206
  /* The server side ignores this unless version >= 1 */
 
207
  req.u.wait.wakeup     = (resume != 0);
184
208
 
185
209
  if (send(HB_INST(iphbh)->fd, &req, sizeof(req), MSG_DONTWAIT|MSG_NOSIGNAL) <= 0)
186
 
    return (time_t)-1;    
 
210
    return (time_t)-1;
187
211
 
188
212
  if (!must_wait)
189
213
    return (time_t)0;
224
248
    return (time_t)-1;
225
249
}
226
250
 
 
251
time_t
 
252
iphb_wait(iphb_t iphbh, unsigned short mintime, unsigned short maxtime, int must_wait)
 
253
{
 
254
  return iphb_wait2(iphbh, mintime, maxtime, must_wait, 1);
 
255
}
 
256
 
227
257
 
228
258
int
229
259
iphb_discard_wakeups(iphb_t iphbh)