Date   

Re: How to store C Arrays as a Property or iVar?

Alex Zavatone
 

You can save them as NSIntegers in an NSMutableArray.

The thing about NSDictionaries and NSArrays is that they need to contain NSObjects that are Cocoa Collections.


Someone please correct me if I’m tragically misguided.

But try that, Dave.

Cheers,
Alex Zavatone

On Aug 18, 2017, at 2:07 PM, Dave <dave@...> wrote:

Hi All,

I’ve converted some C code into Objective-C and have some C Array structures like so:

int [10][10]) myArray;

That I want to store in a Property or iVar inside a Wrapper Class. How do I do this?

I’ve tried:


@interface WrapperClass : NSObect
{
int [10][10]) mArray;
}

But I get an error if I try to assign or read it, as in:

myArray = _mArray;

or

_mArray =  myArray;


Thanks a lot
All the Best
Dave






How to store C Arrays as a Property or iVar?

Dave
 

Hi All,

I’ve converted some C code into Objective-C and have some C Array structures like so:

int [10][10]) myArray;

That I want to store in a Property or iVar inside a Wrapper Class. How do I do this?

I’ve tried:


@interface WrapperClass : NSObect
{
int [10][10]) mArray;
}

But I get an error if I try to assign or read it, as in:

myArray = _mArray;

or

_mArray = myArray;


Thanks a lot
All the Best
Dave


Re: Understanding NSNetService and peer-to-peer streaming

 


On Aug 16, 2017, at 9:24 PM, Graham Cox <graham@...> wrote:

So far, so good. But now I need to return data to the ‘server’ peer. The problem is, I don’t know which stream I need to use to do that. When the ‘server’ accepts a connection, it is handed two streams, which are presumably the ones to use. The problem I have is that these streams are just naked streams - there is no associated information that will tell me which ‘client’ they are connected to.

Right. You need to keep track of that yourself, like with a Peer class that can hold onto those streams and act as their delegate.

I have the idea that what I should do is to wrap the stream pair in another object so I can keep them separate, but that still leaves the problem of identifying that object as being a particular server. I can send that identifying information over the stream the first time I use it, and the ‘client’ can then add that information to the server object, but that seems like a kludge - it is relying on my private protocol to pass information that should already be known to the basic NSNetService infrastructure.

NSNetService doesn't really have anything to do with those streams. All Bonjour does is service discovery: it can advertise a service you're running on some port, and it can find other services of a given type. When it resolves a service it gets the IP address and port number. But that's all Bonjour does.

When you ask an NSNetService to open a connection, it just resolves the service and then calls an NSStream factory method to open a TCP socket to that IP address / port. Then it returns you the resulting streams. Its job is done. This is just a convenience method that was added later on to simplify connecting to services.

Once you've opened the streams, you can remember the name of the service that you got them from. Or you can have a protocol that sends the peer name or UUID or whatever over the socket when it opens; it's up to you.

—Jens

PS: What you're implementing sounds exactly like what the Multipeer Connectivity framework does. Are you aware of it? You could probably save yourself a ton of work by using it.


Re: Understanding NSNetService and peer-to-peer streaming

Quincey Morris
 

On Aug 16, 2017, at 21:24 , Graham Cox <graham@...> wrote:

The problem is, I don’t know which stream I need to use to do that.

I recommend you ask this question in the hated-by-some developer forums (forums.developer.apple.com). Quinn the Eskimo fields questions there most days, and he’s exactly the person to give you the answer. (You might find him on the Apple listserver list for networking too, but I don’t subscribe there.)


Understanding NSNetService and peer-to-peer streaming

Graham Cox
 

Hi all,

I’m trying to add a peer-to-peer communication feature to a game I’m developing.

So far it’s half working, which given the paucity of documentation, I’m actually quite proud of…

Because it’s peer-to-peer, any app can act as both client and server, so getting straight which bit is doing what is quite hard. But for the sake of discussion, I’ll call the service that initiates a connection the server, and the app that receives it the client.

I’m using NSNetService and NSNetServiceBrowser to act as an interface to Bonjour to discover other copies of my game on the network. This part works well - I can advertise myself as a service, and I can receive notifications of other identical services. The ’server' NSNetService receives a -netService:didAcceptConnectionWithInputStream:outputStream:, and schedules those streams in the main run loop and opens them. The ‘server’ also implements -netServiceBrowser:didFindService:moreComing: to wrap the NSNetService representing the client and its streams in a ‘remote player’ object for that client.

I can use the ‘remote player’ object to send data to the client via the streams associated with its NSNetService.

The client receives the data OK, as the stream delegate’s -stream:handleEvent:

So far, so good. But now I need to return data to the ‘server’ peer. The problem is, I don’t know which stream I need to use to do that. When the ‘server’ accepts a connection, it is handed two streams, which are presumably the ones to use. The problem I have is that these streams are just naked streams - there is no associated information that will tell me which ‘client’ they are connected to. At the moment I just schedule these streams in a run loop and open them, and set my general ‘server’ to be their delegate, which is how I am able to receive the data. But given that there will be a pair of these for every connected server, I don’t know which stream to use to return data to a specific server.

I have the idea that what I should do is to wrap the stream pair in another object so I can keep them separate, but that still leaves the problem of identifying that object as being a particular server. I can send that identifying information over the stream the first time I use it, and the ‘client’ can then add that information to the server object, but that seems like a kludge - it is relying on my private protocol to pass information that should already be known to the basic NSNetService infrastructure.

If you’ve followed this, kudos to you. It’s hard to keep straight who is the client and who is the server, to be honest. But even with that muddle, I feel I’m missing something.

If anyone has done something like this successfully and can offer any insights, I’d be most grateful.

—Graham


Re: APFS & FileSystem attributes

Sean McBride
 

On Tue, 15 Aug 2017 22:25:41 +0700, 2551phil said:

I’ve had my head stuck in the sand as far as APFS is concerned (I don’t
have the hardware to test it)"
You could presumably test it in a VM, or using a spare old external drive or USB key, or even just create a disk image. You don't need an extra Mac whose boot disk can be wiped.

Sean


Re: APFS & FileSystem attributes

 


On Aug 15, 2017, at 8:25 AM, 2551phil <2551phil@...> wrote:

I’ve had my head stuck in the sand as far as APFS is concerned (I don’t have the hardware to test it) and only just today suddenly wondered: “hell, it is going to mess up all my FileSystem calls is it?"

It wouldn’t be a valid filesystem if it didn’t support the system calls like stat() that NSFileManager uses to get file attributes.

Now, not every filesystem supports every attribute (you’re not going to get file reference counts on a FAT volume), but since APFS was explicitly designed as the successor to HFS+, I’m pretty certain it supports everything HFS+ does.

—Jens


Re: APFS & FileSystem attributes

2551phil
 

Breaking stuff isn’t always a red line for Apple, but from your reaction I’ll take it that there’d have been an righteous outcry by now were it the case.

I’ve had my head stuck in the sand as far as APFS is concerned (I don’t have the hardware to test it) and only just today suddenly wondered: “hell, it is going to mess up all my FileSystem calls is it?"

Anyway, thanks for the reassurance.


Best


Phil

On 15 Aug 2017, at 22:02, Jens Alfke <jens@mooseyard.com> wrote:


On Aug 15, 2017, at 2:30 AM, 2551phil <2551phil@gmail.com> wrote:

Apologies if this is a dumb question, but I'm wondering whether we'll still be able to call NSFileManager api's like attributesOfItem and get back things like NSFileReferenceCount and the like.
Does APFS make any difference to this?
If it did, it would break most apps, so no.

—Jens




Re: APFS & FileSystem attributes

 

On Aug 15, 2017, at 2:30 AM, 2551phil <2551phil@gmail.com> wrote:

Apologies if this is a dumb question, but I'm wondering whether we'll still be able to call NSFileManager api's like attributesOfItem and get back things like NSFileReferenceCount and the like.
Does APFS make any difference to this?
If it did, it would break most apps, so no.

—Jens


APFS & FileSystem attributes

2551phil
 

Apologies if this is a dumb question, but I'm wondering whether we'll still be able to call NSFileManager api's like attributesOfItem and get back things like NSFileReferenceCount and the like. 

Does APFS make any difference to this?


TIA


Phil


Re: "broken pipe", but not when debugging...

Jack Brindle
 

Jens;
Thank you for the opportunity to expound on this. See below…

On Aug 11, 2017, at 9:48 AM, Jens Alfke <jens@...> wrote:


On Aug 10, 2017, at 9:30 PM, Graham Cox <graham@...> wrote:

I can’t find any mention of functions called signal() or ioctl() in the current (Xcode 8) documentation browser. But then, it seems we’ve lost the ability to view man pages. WTF, why are we going backwards with every “update”?

It does seem absurd that the most fundamental APIs — the C standard library and POSIX/Darwin system calls — aren’t supported by Xcode’s documentation features. Especially since the header files give zero information, usually not even parameter names. I assume this is something hundreds of people have already filed bug reports about over the years. 

I just end up typing “man foo” in a Terminal window, or using the awesome Dash app.


Jack Brindle wrote:

Be sure and put the data write into a try-catch block in order
to catch the broken pipe (assuming it occurs on a write). This is actually documented, but I’ll have to go find it to say. My notes indicate the
docs to say: This method raises an exception if the file descriptor is closed or is not valid, if the receiver represents an unconnected pipe
or socket endpoint, if no free space is left on the file system, or if any other writing error occurs.

I think this is a separate (but related) issue. NSTask is one of the few Cocoa APIs that will throw exceptions in ‘normal’ use to indicate a runtime error, so your advice is correct. But the SIGPIPE crash is different — signals are not exceptions, they’re an earlier lower-level mechanism.

A look at the discussion for NSFileHandle’s writeData: method provides the following:
"This method raises an exception if the file descriptor is closed or is not valid, if the receiver represents an unconnected pipe or socket endpoint, if no free space is left on the file system, or if any other writing error occurs.

The exception is caused directly by the broken pipe. The exception handler is picking it up so that a try-catch block can directly handle and correct for it. The same text is in the availableData method. I tend to be very defensive in my code, especially in areas where
external forces can cause problems. This is one such area. After I started using try-catch blocks around these methods the crash issues disappeared.

I believe there are many other issues that the Cocoa frameworks handle with exceptions that we used to handle otherwise - that is with signal handling. I still have some signal handling code, but for the most part it has mostly gone away as we move more into the
try-catch exception handling world. Perhaps this is why it is more difficult to find docs for this things. Having said that, ioctl is so important that it must be available.

In any case, learning to use try-catch has been very beneficial!

- Jack


—Jens


Re: "broken pipe", but not when debugging...

 


On Aug 10, 2017, at 9:30 PM, Graham Cox <graham@...> wrote:

I can’t find any mention of functions called signal() or ioctl() in the current (Xcode 8) documentation browser. But then, it seems we’ve lost the ability to view man pages. WTF, why are we going backwards with every “update”?

It does seem absurd that the most fundamental APIs — the C standard library and POSIX/Darwin system calls — aren’t supported by Xcode’s documentation features. Especially since the header files give zero information, usually not even parameter names. I assume this is something hundreds of people have already filed bug reports about over the years. 

I just end up typing “man foo” in a Terminal window, or using the awesome Dash app.


Jack Brindle wrote:

Be sure and put the data write into a try-catch block in order
to catch the broken pipe (assuming it occurs on a write). This is actually documented, but I’ll have to go find it to say. My notes indicate the
docs to say: This method raises an exception if the file descriptor is closed or is not valid, if the receiver represents an unconnected pipe
or socket endpoint, if no free space is left on the file system, or if any other writing error occurs.

I think this is a separate (but related) issue. NSTask is one of the few Cocoa APIs that will throw exceptions in ‘normal’ use to indicate a runtime error, so your advice is correct. But the SIGPIPE crash is different — signals are not exceptions, they’re an earlier lower-level mechanism.

—Jens


Re: (OT) Image Editing App for Mac?

Jim
 

On Aug 11, 2017, at 9:34 AM, Dave <dave@looktowindward.com> wrote:

Can anyone recommend a light weight Image Creation and Editing App for the Mac?

I’d like to be able to create images with fixed dimensions and background colour and be able to resize images.

Basically I need some text (separate letters/numerals mostly, (“A” to “Z”, “0” to “9”)) of a fixed size. Although I can take screen dumps and resize if necessary.
I’ve been happy with Acorn for those purposes for years. The documentation is great too.

https://flyingmeat.com

Jim Crate


Re: (OT) Image Editing App for Mac?

Sandor Szatmari
 

Try canva.com. They have a reasonable free account for graphics editing online, apparently they have an iOS app too, although I've never tried that.

Sandor

On Aug 11, 2017, at 10:14, Andreas Mayer <andreas@harmless.de> wrote:


Am 11.08.2017 um 15:34 schrieb Dave <dave@looktowindward.com>:

Basically I need some text (separate letters/numerals mostly, (“A” to “Z”, “0” to “9”)) of a fixed size.
Um... I might just write code to do that. The 'hardest' thing is probably to get text positioning right.

For general image manipulation I use Pixelmator. I like it but I wouldn't exactly call it light weight.

Or, for vector graphics, there's Affinity Designer. Not light weight either but will work well for what you plan to do.


Andreas


Re: (OT) Image Editing App for Mac?

Andreas Mayer
 

Am 11.08.2017 um 15:34 schrieb Dave <dave@looktowindward.com>:

Basically I need some text (separate letters/numerals mostly, (“A” to “Z”, “0” to “9”)) of a fixed size.
Um... I might just write code to do that. The 'hardest' thing is probably to get text positioning right.

For general image manipulation I use Pixelmator. I like it but I wouldn't exactly call it light weight.

Or, for vector graphics, there's Affinity Designer. Not light weight either but will work well for what you plan to do.


Andreas


Re: (OT) Image Editing App for Mac?

Jim Adams
 

How about Gimp?

On Aug 11, 2017, at 9:34 AM, Dave <dave@looktowindward.com> wrote:

EXTERNAL

Hi,

Can anyone recommend a light weight Image Creation and Editing App for the Mac?

I’d like to be able to create images with fixed dimensions and background colour and be able to resize images.

Basically I need some text (separate letters/numerals mostly, (“A” to “Z”, “0” to “9”)) of a fixed size. Although I can take screen dumps and resize if necessary.

I usually use Photoshop, but I don’t have installed on this machine and I’m travelling, I will install it when I get back, but I need something in the mean time…….

All the Best
Dave




(OT) Image Editing App for Mac?

Dave
 

Hi,

Can anyone recommend a light weight Image Creation and Editing App for the Mac?

I’d like to be able to create images with fixed dimensions and background colour and be able to resize images.

Basically I need some text (separate letters/numerals mostly, (“A” to “Z”, “0” to “9”)) of a fixed size. Although I can take screen dumps and resize if necessary.

I usually use Photoshop, but I don’t have installed on this machine and I’m travelling, I will install it when I get back, but I need something in the mean time…….

All the Best
Dave


CGImage for writing large multi-page tiffs?

Jonathan Taylor
 

Hi all,

At the moment I am saving tiff files in a one-liner using [[myNSImage TIFFRepresentation] writeToFile:atomically:]. I am considering a change to write rather large multi-page tiff files instead of individual files, and am trying to think through the memory implications. The individual images effectively represent single frames of realtime video, which at the moment are written to individual tiff files.

I have two possible concerns over performance, if I switch to writing multi-page tiffs. The first is that that one-liner is going to be doing a lot of work (assembling the tiff data, and writing to disk) in one chunk, instead of spreading it out more evenly over time. The other is that I am going to be accumulating a lot of image data in memory before writing it. That ~might~ be undesirable from a cache point of view, but more importantly I will need to make sure I don’t risk filling up the 32-bit address space. Yes, unfortunately for driver compatibility reasons I am stuck with a 32-bit build here.

I had a quick look around for alternatives to NSImage. It looks as if the CGImage API is more set up for adding images one-by-one to a CGImageDestination, before eventually calling CGImageDestinationFinalize. It’s very possible, though, that behind the scenes the CGImageDestination is just doing the caching in memory itself, before still doing one big write to disk in Finalize. I couldn’t immediately find any documentation about whether there are any such guarantees about performance, nor could I see any way of encouraging it to flush to disk incrementally. Can anyone offer any advice on that?

The other option would be to look for a third-party library. It looks like libtiff would be an option (which supports incremental flushing), but that looks like it’s a lower-level API than I would ideally need. Does anyone have any other recommendations?

Thanks for any suggestions.
Cheers
Jonny


Re: "broken pipe", but not when debugging...

Jonathan Prescott
 

Look at fcntl() (man fcntl). It has an operation parameter of F_SETNOSIGPIPE and F_GETNOSIGPIPE to manage the SIGPIPE signal handling on a file descriptor. Won’t find it in the Xcode documentation, but it is in the BSD man pages.

Jonathan

On Aug 11, 2017, at 12:30 AM, Graham Cox <graham@mapdiva.com> wrote:


On 11 Aug 2017, at 1:42 pm, Graham Cox <graham@mapdiva.com> wrote:

Traditionally the workaround has been to call signal() to install a process-wide no-op handler for SIGPIPE, but on Apple platforms (and others?) you can also set a flag on the file descriptor telling it not to raise the signal. I was going to write that it’s an option to setsockopt, but then I remembered you’re using a pipe not a socket. So I’m not sure what system call you’d use; ioctl maybe?

OK, I’ll look into doing something like this.

Well, this is so far a blind alley.

I can’t find any mention of functions called signal() or ioctl() in the current (Xcode 8) documentation browser. But then, it seems we’ve lost the ability to view man pages. WTF, why are we going backwards with every “update”?

Assume I’m only 5. Where to I find those functions and some sort of documentation for them?

—Graham





Re: "broken pipe", but not when debugging...

Jack Brindle
 

A broken pipe usually means that one end of the connection has been closed for one reason or another. You don’t show the actual
read and write code, but that is most likely where the problem occurs. Be sure and put the data write into a try-catch block in order
to catch the broken pipe (assuming it occurs on a write). This is actually documented, but I’ll have to go find it to say. My notes indicate the
docs to say: This method raises an exception if the file descriptor is closed or is not valid, if the receiver represents an unconnected pipe
or socket endpoint, if no free space is left on the file system, or if any other writing error occurs. The catch block should set pretty much all the
handles to nil, especially the read handle.readabilityHandler. It is pretty easy and useful to set up the readabilityHandler block to get the
data coming from the executable.

This is a two-way street, and it is likely the other end is participating in the broken pipe, if not actually throwing it. If your pipes are not set
up properly and it tries to write to its stdout, you will see this issue.

Also, it might be helpful to debug the son an El Capitan system where we still have a good logging system.

One thing that does look slightly strange is the way the arguments are set up. NSTask really would like for each item to be in a separate
entry (i.e. @[@“ponder”, @“off”, @“noise”, @“1000000”…]. I don’t know if it makes any difference, but is worth trying.

This stuff works pretty well, but there is a lot of opportunity to get broken pipes when one side shuts down for any reason, or simply
closes their side of the connection. Try-catch is definitely your friend here, on both sides of the connection.

- Jack

On Aug 10, 2017, at 4:12 PM, Graham Cox <graham@mapdiva.com> wrote:

Hi,

I’m using NSTask to ‘talk to’ a command line executable that is embedded in my app. I use NSPipe as its stdIn and stdOut channels.
When I run the code under Xcode, it works fine. When I build the app into a standalone executable, it fails with a “broken pipe 13” error message and immediate termination.

Aug 11 09:01:23 The-New-iMac com.apple.xpc.launchd[1] (net.apptree.checkmate.Checkmate.61324[49384]): Service exited due to signal: Broken pipe: 13 sent by Checkmate[49384]

The code seems pretty straightforward, so I can’t see anything tricky. Any ideas what could be causing this?


NSBundle* mainBundle = [NSBundle mainBundle];
NSString* executablePath = [mainBundle pathForAuxiliaryExecutable:@"crafty"];
NSString* resourcePath = [mainBundle resourcePath];

mCrafty = [[NSTask alloc] init];

mCrafty.launchPath = executablePath;
mCrafty.arguments = @[@"ponder off",@"noise 1000000",@"sn 10",@"sd 10"];

NSMutableDictionary* environment = [NSMutableDictionary dictionary];

[environment setObject:resourcePath forKey:@"CRAFTY_BOOK_PATH"];

mCrafty.environment = environment;

[self initStdIn];
[self initStdOut];

NSLog(@"launching crafty");

[mCrafty launch];




- (void) initStdIn
{
NSPipe* inputToCrafty = [NSPipe pipe];

mCrafty.standardInput = inputToCrafty;

NSLog(@"stdIn initialized");
}



- (void) initStdOut
{
NSPipe* craftyOutput = [NSPipe pipe];

craftyOutput.fileHandleForReading.readabilityHandler = ^(NSFileHandle* fileHandle)
{
//[all the stuff that parses the output deleted for clarity]
};

mCrafty.standardOutput = craftyOutput;

NSLog(@"stdOut initialized");
}


Note: For the standalone executable, I don’t see any of the logged (NSLog) messages. I’m not sure why. One difficulty is that the revised Console app makes it a lot harder to figure out what the hell I’m looking at. system.log contains the SIGPIPE error, but none of the log messages. Where did they go?

—Graham





1241 - 1260 of 1427