Re: CFSocket Callback
Re: CFSocket Callback
- Subject: Re: CFSocket Callback
- From: Becky Willrich <email@hidden>
- Date: Mon, 9 Sep 2002 10:22:52 -0700
Depending on what you want to do, either just use
CFDataGetBytePtr(data) as a char[] (possibly copying it first, if
you're not going to use it immediately), or use the CFString creation
methods to build a true CFString. If you're sure you're working with
plain old ASCII and really want a normal, NULL-terminated char *, this
should work (not compiled/tested):
void whatToDo(CFSocketRef s, CFSocketCallBackType type, CFDataRef
address, const void *data, void *info)
{
int length = CFDataGetLength(data);
char *newString = malloc(length+1);
memmove(newString, CFDataGetBytePtr(data), length);
newString[length] = '\0';
}
REW
On Monday, September 9, 2002, at 09:40 AM, Edward Fink wrote:
How do I get the data returned from a CFSocket callback into a regular
string ( char[ ] ) ?
Using something similar to the following I can printf the data, but I
haven't figured out how
to get it into a regular string for manipulation.
Any ideas?
void whatToDo(CFSocketRef s, CFSocketCallBackType type, CFDataRef
address, const void *data, void *info)
{
printf ("%.*s\n\n", (int)CFDataGetLength(data),
CFDataGetBytePtr(data));
}
CFSocketRef s = CFSocketCreate(NULL, PF_INET, SOCK_STREAM, IPPROTO_TCP,
kCFSocketDataCallBack, whatToDo,
NULL);
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.