Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TLMSP curl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CYBER - Cyber Security
TS 103 523 MSP
TLMSP
TLMSP curl
Commits
ad361d10
Commit
ad361d10
authored
12 years ago
by
Daniel Stenberg
Browse files
Options
Downloads
Patches
Plain Diff
hiperfifo: updated to use current libevent API
Patch by: Myk Taylor
parent
1fcf52ca
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/examples/hiperfifo.c
+42
-24
42 additions, 24 deletions
docs/examples/hiperfifo.c
with
42 additions
and
24 deletions
docs/examples/hiperfifo.c
+
42
−
24
View file @
ad361d10
...
...
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 201
1
, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 201
3
, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
...
...
@@ -24,7 +24,7 @@
Written by Jeff Pohlmeyer
Requires libevent and a (POSIX?) system that has mkfifo().
Requires libevent
version 2
and a (POSIX?) system that has mkfifo().
This is an adaptation of libcurl's "hipev.c" and libevent's "event-test.c"
sample programs.
...
...
@@ -61,7 +61,7 @@ callback.
#include
<unistd.h>
#include
<sys/poll.h>
#include
<curl/curl.h>
#include
<event.h>
#include
<
event2/
event.h>
#include
<fcntl.h>
#include
<sys/stat.h>
#include
<errno.h>
...
...
@@ -71,9 +71,11 @@ callback.
/* Global information, common to all connections */
typedef
struct
_GlobalInfo
{
struct
event
fifo_event
;
struct
event
timer_event
;
typedef
struct
_GlobalInfo
{
struct
event_base
*
evbase
;
struct
event
*
fifo_event
;
struct
event
*
timer_event
;
CURLM
*
multi
;
int
still_running
;
FILE
*
input
;
...
...
@@ -81,7 +83,8 @@ typedef struct _GlobalInfo {
/* Information associated with a specific easy handle */
typedef
struct
_ConnInfo
{
typedef
struct
_ConnInfo
{
CURL
*
easy
;
char
*
url
;
GlobalInfo
*
global
;
...
...
@@ -90,12 +93,13 @@ typedef struct _ConnInfo {
/* Information associated with a specific socket */
typedef
struct
_SockInfo
{
typedef
struct
_SockInfo
{
curl_socket_t
sockfd
;
CURL
*
easy
;
int
action
;
long
timeout
;
struct
event
ev
;
struct
event
*
ev
;
int
evset
;
GlobalInfo
*
global
;
}
SockInfo
;
...
...
@@ -111,7 +115,7 @@ static int multi_timer_cb(CURLM *multi, long timeout_ms, GlobalInfo *g)
timeout
.
tv_sec
=
timeout_ms
/
1000
;
timeout
.
tv_usec
=
(
timeout_ms
%
1000
)
*
1000
;
fprintf
(
MSG_OUT
,
"multi_timer_cb: Setting timeout to %ld ms
\n
"
,
timeout_ms
);
evtimer_add
(
&
g
->
timer_event
,
&
timeout
);
evtimer_add
(
g
->
timer_event
,
&
timeout
);
return
0
;
}
...
...
@@ -186,8 +190,8 @@ static void event_cb(int fd, short kind, void *userp)
check_multi_info
(
g
);
if
(
g
->
still_running
<=
0
)
{
fprintf
(
MSG_OUT
,
"last transfer done, kill timeout
\n
"
);
if
(
evtimer_pending
(
&
g
->
timer_event
,
NULL
))
{
evtimer_del
(
&
g
->
timer_event
);
if
(
evtimer_pending
(
g
->
timer_event
,
NULL
))
{
evtimer_del
(
g
->
timer_event
);
}
}
}
...
...
@@ -215,7 +219,7 @@ static void remsock(SockInfo *f)
{
if
(
f
)
{
if
(
f
->
evset
)
event_
del
(
&
f
->
ev
);
event_
free
(
f
->
ev
);
free
(
f
);
}
}
...
...
@@ -232,16 +236,17 @@ static void setsock(SockInfo*f, curl_socket_t s, CURL*e, int act, GlobalInfo*g)
f
->
action
=
act
;
f
->
easy
=
e
;
if
(
f
->
evset
)
event_
del
(
&
f
->
ev
);
event_set
(
&
f
->
ev
,
f
->
sockfd
,
kind
,
event_cb
,
g
);
f
->
evset
=
1
;
event_add
(
&
f
->
ev
,
NULL
);
event_
free
(
f
->
ev
);
f
->
ev
=
event_new
(
g
->
evbase
,
f
->
sockfd
,
kind
,
event_cb
,
g
);
f
->
evset
=
1
;
event_add
(
f
->
ev
,
NULL
);
}
/* Initialize a new SockInfo structure */
static
void
addsock
(
curl_socket_t
s
,
CURL
*
easy
,
int
action
,
GlobalInfo
*
g
)
{
static
void
addsock
(
curl_socket_t
s
,
CURL
*
easy
,
int
action
,
GlobalInfo
*
g
)
{
SockInfo
*
fdp
=
calloc
(
sizeof
(
SockInfo
),
1
);
fdp
->
global
=
g
;
...
...
@@ -359,10 +364,10 @@ static void fifo_cb(int fd, short event, void *arg)
}
/* Create a named pipe and tell libevent to monitor it */
static
const
char
*
fifo
=
"hiper.fifo"
;
static
int
init_fifo
(
GlobalInfo
*
g
)
{
struct
stat
st
;
static
const
char
*
fifo
=
"hiper.fifo"
;
curl_socket_t
sockfd
;
fprintf
(
MSG_OUT
,
"Creating named pipe
\"
%s
\"\n
"
,
fifo
);
...
...
@@ -386,11 +391,18 @@ static int init_fifo (GlobalInfo *g)
g
->
input
=
fdopen
(
sockfd
,
"r"
);
fprintf
(
MSG_OUT
,
"Now, pipe some URL's into > %s
\n
"
,
fifo
);
event_set
(
&
g
->
fifo_event
,
sockfd
,
EV_READ
|
EV_PERSIST
,
fifo_cb
,
g
);
event_add
(
&
g
->
fifo_event
,
NULL
);
g
->
fifo_event
=
event_new
(
g
->
evbase
,
sockfd
,
EV_READ
|
EV_PERSIST
,
fifo_cb
,
g
);
event_add
(
g
->
fifo_event
,
NULL
);
return
(
0
);
}
static
void
clean_fifo
(
GlobalInfo
*
g
)
{
event_free
(
g
->
fifo_event
);
fclose
(
g
->
input
);
unlink
(
fifo
);
}
int
main
(
int
argc
,
char
**
argv
)
{
GlobalInfo
g
;
...
...
@@ -398,10 +410,10 @@ int main(int argc, char **argv)
(
void
)
argv
;
memset
(
&
g
,
0
,
sizeof
(
GlobalInfo
));
event_init
();
g
.
evbase
=
event_base_new
();
init_fifo
(
&
g
);
g
.
multi
=
curl_multi_init
();
ev
timer_
set
(
&
g
.
timer_event
,
timer_cb
,
&
g
);
g
.
timer_
event
=
evtimer_new
(
g
.
evbase
,
timer_cb
,
&
g
);
/* setup the generic multi interface options we want */
curl_multi_setopt
(
g
.
multi
,
CURLMOPT_SOCKETFUNCTION
,
sock_cb
);
...
...
@@ -412,7 +424,13 @@ int main(int argc, char **argv)
/* we don't call any curl_multi_socket*() function yet as we have no handles
added! */
event_dispatch
();
event_base_dispatch
(
g
.
evbase
);
/* this, of course, won't get called since only way to stop this program is
via ctrl-C, but it is here to show how cleanup /would/ be done. */
clean_fifo
(
&
g
);
event_free
(
g
.
timer_event
);
event_base_free
(
g
.
evbase
);
curl_multi_cleanup
(
g
.
multi
);
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment